Example usage for java.awt GridBagConstraints NONE

List of usage examples for java.awt GridBagConstraints NONE

Introduction

In this page you can find the example usage for java.awt GridBagConstraints NONE.

Prototype

int NONE

To view the source code for java.awt GridBagConstraints NONE.

Click Source Link

Document

Do not resize the component.

Usage

From source file:de.fhg.igd.iva.explorer.main.CompareViewPanel.java

protected void updateSelection() {
    KnownColormap colormap = (KnownColormap) mapsCombo.getSelectedItem();

    cmView.setColormap(colormap);/*from  w  w w . j a  v  a2  s . co m*/

    statsBars.removeAll();

    Map<ColormapQuality, Double> row = table.row(colormap);

    Insets insets = new Insets(0, 0, 0, 0);
    Insets insets5 = new Insets(0, 5, 0, 0);

    GridBagConstraints gbcName = new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.NONE, insets, 0, 0);
    GridBagConstraints gbcQual = new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcRank = new GridBagConstraints(2, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcStatL = new GridBagConstraints(3, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcStatR = new GridBagConstraints(4, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_END,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcStat = new GridBagConstraints(3, 0, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.HORIZONTAL, insets5, 0, 0);

    statsBars.add(new JLabel("Name"), gbcName);
    statsBars.add(new JLabel("Score"), gbcQual);
    statsBars.add(new JLabel("Rank"), gbcRank);

    // maybe use a best/worst arrow down marker instead? unicode: \u2193
    statsBars.add(new JLabel("\u2190Worse"), gbcStatL);
    statsBars.add(new JLabel("Better\u2192"), gbcStatR);

    GridBagConstraints gbcSpace = new GridBagConstraints(0, 1, 5, 1, 1.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0);
    JSeparator spacing = new JSeparator(SwingConstants.HORIZONTAL);
    statsBars.add(spacing, gbcSpace);

    int count = table.rowKeySet().size();

    int rowIdx = 2;
    for (ColormapQuality metric : row.keySet()) {
        double quality = row.get(metric);
        DescriptiveStatistics stats = computeStats(metric);
        int index = Arrays.binarySearch(stats.getSortedValues(), quality);

        int rank = metric.moreIsBetter() ? count - index : index + 1;

        gbcName = (GridBagConstraints) gbcName.clone();
        gbcQual = (GridBagConstraints) gbcQual.clone();
        gbcRank = (GridBagConstraints) gbcRank.clone();
        gbcStat = (GridBagConstraints) gbcStat.clone();

        gbcName.gridy = rowIdx;
        gbcQual.gridy = rowIdx;
        gbcRank.gridy = rowIdx;
        gbcStat.gridy = rowIdx;

        statsBars.add(new JLabel(metric.getName()), gbcName);
        statsBars.add(new JLabel(String.format("%.2f", quality)), gbcQual);
        statsBars.add(new JLabel(Integer.toString(rank)), gbcRank);
        statsBars.add(new JStatBar(metric, stats, quality), gbcStat);
        rowIdx++;
    }

    // I find it strange that both revalidate and repaint must be explicitly called here
    revalidate();
    repaint();
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.ResultatPanel.java

public ResultatPanel() {
    this.setLayout(new GridBagLayout());
    final GridBagConstraints c = new DefaultGridBagConstraints();

    this.add(new JLabel("Vous allez gnrer le fichier result_2033B.pdf contenant le rsultat."), c);
    c.gridy++;/*  ww w. jav  a  2  s.c o  m*/
    try {
        this.add(new JLabel("Il se trouvera dans le dossier "
                + new File(TemplateNXProps.getInstance().getStringProperty("Location2033BPDF"))
                        .getCanonicalPath()),
                c);
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    final JButton buttonFermer = new JButton("Fermer");
    buttonFermer.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            ((JFrame) SwingUtilities.getRoot(ResultatPanel.this)).dispose();
        }
    });

    final JButton buttonOuvrir = new JButton("Ouvrir dossier");
    buttonOuvrir.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            final String file = TemplateNXProps.getInstance().getStringProperty("Location2033BPDF");
            File f = new File(file);
            FileUtils.browseFile(f);
        }
    });

    // FIXME impossible de gnrer si le fichier est ouvert
    final JButton buttonGenerer = new JButton("Gnrer");
    buttonGenerer.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            final Map2033B map = new Map2033B(new JProgressBar());
            map.generateMap();
        }
    });

    c.gridx = GridBagConstraints.RELATIVE;
    c.gridwidth = 1;
    c.weightx = 0;
    c.fill = GridBagConstraints.NONE;
    this.add(buttonOuvrir, c);

    c.gridy++;
    c.anchor = GridBagConstraints.EAST;
    c.weightx = 1;
    buttonGenerer.setHorizontalAlignment(SwingConstants.RIGHT);
    this.add(buttonGenerer, c);
    c.weightx = 0;
    this.add(buttonFermer, c);
}

From source file:PizzaGridBagLayout.java

private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align) {
    GridBagConstraints gc = new GridBagConstraints();
    gc.gridx = x;//ww  w  .  ja v a  2s  .  c om
    gc.gridy = y;
    gc.gridwidth = width;
    gc.gridheight = height;
    gc.weightx = 100.0;
    gc.weighty = 100.0;
    gc.insets = new Insets(5, 5, 5, 5);
    gc.anchor = align;
    gc.fill = GridBagConstraints.NONE;
    p.add(c, gc);
}

From source file:org.apache.marmotta.splash.common.ui.SelectionDialog.java

public static int select(String title, String message, String description, List<Option> options,
        int defaultOption) {
    final JDialog dialog = new JDialog((Frame) null, title);
    dialog.setModal(true);//from  w ww .  j  av  a2s .com
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    final AtomicInteger result = new AtomicInteger(Math.max(defaultOption, -1));

    JButton defaultBtn = null;

    final JPanel root = new JPanel(new GridBagLayout());
    root.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    dialog.getRootPane().setContentPane(root);

    JLabel lblMsg = new JLabel("<html>" + StringEscapeUtils.escapeHtml3(message).replaceAll("\\n", "<br>"));
    lblMsg.setFont(lblMsg.getFont().deriveFont(Font.BOLD, 16f));
    GridBagConstraints cLabel = new GridBagConstraints();
    cLabel.gridx = 0;
    cLabel.gridy = 0;
    cLabel.fill = GridBagConstraints.BOTH;
    cLabel.weightx = 1;
    cLabel.weighty = 0.5;
    cLabel.insets = new Insets(5, 5, 5, 5);
    root.add(lblMsg, cLabel);

    JLabel lblDescr = new JLabel(
            "<html>" + StringEscapeUtils.escapeHtml3(description).replaceAll("\\n", "<br>"));
    cLabel.gridy++;
    cLabel.insets = new Insets(0, 5, 5, 5);
    root.add(lblDescr, cLabel);

    // All the options
    cLabel.ipadx = 10;
    cLabel.ipady = 10;
    cLabel.insets = new Insets(5, 15, 0, 15);
    for (int i = 0; i < options.size(); i++) {
        cLabel.gridy++;

        final Option o = options.get(i);
        final JButton btn = new JButton(
                "<html>" + StringEscapeUtils.escapeHtml3(o.label).replaceAll("\\n", "<br>"),
                MessageDialog.loadIcon(o.icon));
        if (StringUtils.isNotBlank(o.info)) {
            btn.setToolTipText("<html>" + StringEscapeUtils.escapeHtml3(o.info).replaceAll("\\n", "<br>"));
        }

        btn.setHorizontalAlignment(AbstractButton.LEADING);
        btn.setVerticalTextPosition(AbstractButton.CENTER);
        btn.setHorizontalTextPosition(AbstractButton.TRAILING);

        final int myAnswer = i;
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                result.set(myAnswer);
                dialog.setVisible(false);
            }
        });

        root.add(btn, cLabel);
        if (i == defaultOption) {
            dialog.getRootPane().setDefaultButton(btn);
            defaultBtn = btn;
        }
    }

    final Icon icon = MessageDialog.loadIcon();
    if (icon != null) {
        JLabel lblIcn = new JLabel(icon);

        GridBagConstraints cIcon = new GridBagConstraints();
        cIcon.gridx = 1;
        cIcon.gridy = 0;
        cIcon.gridheight = 2 + options.size();
        cIcon.fill = GridBagConstraints.NONE;
        cIcon.weightx = 0;
        cIcon.weighty = 1;
        cIcon.anchor = GridBagConstraints.NORTH;
        cIcon.insets = new Insets(10, 5, 5, 0);
        root.add(lblIcn, cIcon);
    }

    final JButton close = new JButton("Cancel");
    close.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            result.set(-1);
            dialog.setVisible(false);
        }
    });
    GridBagConstraints cClose = new GridBagConstraints();
    cClose.gridx = 0;
    cClose.gridy = 2 + options.size();
    cClose.gridwidth = 2;
    cClose.weightx = 1;
    cClose.weighty = 0;
    cClose.insets = new Insets(15, 5, 5, 5);

    root.add(close, cClose);
    if (defaultOption < 0) {
        dialog.getRootPane().setDefaultButton(close);
        defaultBtn = close;
    }

    dialog.pack();
    dialog.setLocationRelativeTo(null);
    defaultBtn.requestFocusInWindow();

    dialog.setVisible(true);
    dialog.dispose();

    return result.get();
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.BilanPanel.java

public BilanPanel() {
    this.setLayout(new GridBagLayout());
    final GridBagConstraints c = new DefaultGridBagConstraints();

    this.add(new JLabel("Vous allez gnrer le fichier result_2033A.pdf contenant le bilan simplifi."), c);
    c.gridy++;/*from  ww  w .  j a v a 2 s .c  om*/
    try {
        this.add(new JLabel("Il se trouvera dans le dossier "
                + new File(TemplateNXProps.getInstance().getStringProperty("Location2033APDF"))
                        .getCanonicalPath()),
                c);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    /*
     * PdfGenerator_2033A p = new PdfGenerator_2033A(); p.generateFrom(new
     * Map2033A().getMap2033A());
     */

    JButton buttonFermer = new JButton("Fermer");
    buttonFermer.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            ((JFrame) SwingUtilities.getRoot(BilanPanel.this)).dispose();
        }
    });

    JButton buttonOuvrirDossier = new JButton("Ouvrir dossier");
    buttonOuvrirDossier.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String file = TemplateNXProps.getInstance().getStringProperty("Location2033APDF");
            File f = new File(file);
            FileUtils.browseFile(f);
        };
    });

    // FIXME impossible de gnrer si le fichier est ouvert
    JButton buttonGenerer = new JButton("Gnrer");
    buttonGenerer.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            Map2033A map = new Map2033A(new JProgressBar());
            map.generateMap2033A();
        };
    });

    c.gridx = GridBagConstraints.RELATIVE;
    c.gridwidth = 1;
    c.weightx = 0;
    c.fill = GridBagConstraints.NONE;
    this.add(buttonOuvrirDossier, c);

    c.gridy++;
    c.anchor = GridBagConstraints.EAST;
    c.weightx = 1;
    buttonGenerer.setHorizontalAlignment(SwingConstants.RIGHT);
    this.add(buttonGenerer, c);
    c.weightx = 0;
    this.add(buttonFermer, c);
}

From source file:net.sf.jabref.gui.preftabs.PreviewPrefsTab.java

public PreviewPrefsTab(JabRefPreferences prefs) {
    this.prefs = prefs;

    GridBagLayout layout = new GridBagLayout();
    firstPanel.setLayout(layout);/* w  w w .  j  a v a  2  s .c  o m*/
    secondPanel.setLayout(layout);

    setLayout(layout);
    JLabel lab = new JLabel(Localization.lang("Preview") + " 1");
    GridBagConstraints layoutConstraints = new GridBagConstraints();
    layoutConstraints.anchor = GridBagConstraints.WEST;
    layoutConstraints.gridwidth = GridBagConstraints.REMAINDER;
    layoutConstraints.fill = GridBagConstraints.BOTH;
    layoutConstraints.weightx = 1;
    layoutConstraints.weighty = 0;
    layoutConstraints.insets = new Insets(2, 2, 2, 2);
    layout.setConstraints(lab, layoutConstraints);
    layoutConstraints.weighty = 1;
    layout.setConstraints(firstScrollPane, layoutConstraints);
    firstPanel.add(firstScrollPane);
    layoutConstraints.weighty = 0;
    layoutConstraints.gridwidth = 1;
    layoutConstraints.weightx = 0;
    layoutConstraints.fill = GridBagConstraints.NONE;
    layoutConstraints.anchor = GridBagConstraints.WEST;
    layout.setConstraints(testButton, layoutConstraints);
    firstPanel.add(testButton);
    layout.setConstraints(defaultButton, layoutConstraints);
    firstPanel.add(defaultButton);
    layoutConstraints.gridwidth = GridBagConstraints.REMAINDER;
    JPanel newPan = new JPanel();
    layoutConstraints.weightx = 1;
    layout.setConstraints(newPan, layoutConstraints);
    firstPanel.add(newPan);
    lab = new JLabel(Localization.lang("Preview") + " 2");
    layout.setConstraints(lab, layoutConstraints);
    // p2.add(lab);
    layoutConstraints.weighty = 1;
    layoutConstraints.fill = GridBagConstraints.BOTH;
    layout.setConstraints(secondScrollPane, layoutConstraints);
    secondPanel.add(secondScrollPane);
    layoutConstraints.weighty = 0;
    layoutConstraints.weightx = 0;
    layoutConstraints.fill = GridBagConstraints.NONE;
    layoutConstraints.gridwidth = 1;
    layout.setConstraints(testButton2, layoutConstraints);
    secondPanel.add(testButton2);
    layout.setConstraints(defaultButton2, layoutConstraints);
    secondPanel.add(defaultButton2);
    layoutConstraints.gridwidth = 1;
    newPan = new JPanel();
    layoutConstraints.weightx = 1;
    layout.setConstraints(newPan, layoutConstraints);
    secondPanel.add(newPan);

    layoutConstraints.weightx = 1;
    layoutConstraints.weighty = 0;
    layoutConstraints.fill = GridBagConstraints.BOTH;
    layoutConstraints.gridwidth = GridBagConstraints.REMAINDER;
    lab = new JLabel(Localization.lang("Preview") + " 1");
    layout.setConstraints(lab, layoutConstraints);
    add(lab);
    layoutConstraints.weighty = 1;
    layout.setConstraints(firstPanel, layoutConstraints);
    add(firstPanel);
    lab = new JLabel(Localization.lang("Preview") + " 2");
    layoutConstraints.weighty = 0;
    JSeparator sep = new JSeparator(SwingConstants.HORIZONTAL);
    layout.setConstraints(sep, layoutConstraints);
    add(sep);
    layout.setConstraints(lab, layoutConstraints);
    add(lab);
    layoutConstraints.weighty = 1;
    layout.setConstraints(secondPanel, layoutConstraints);
    add(secondPanel);
    layoutConstraints.weighty = 0;

    defaultButton.addActionListener(e -> {
        String tmp = layout1.getText().replace("\n", "__NEWLINE__");
        PreviewPrefsTab.this.prefs.remove(JabRefPreferences.PREVIEW_0);
        layout1.setText(
                PreviewPrefsTab.this.prefs.get(JabRefPreferences.PREVIEW_0).replace("__NEWLINE__", "\n"));
        PreviewPrefsTab.this.prefs.put(JabRefPreferences.PREVIEW_0, tmp);
    });

    defaultButton2.addActionListener(e -> {
        String tmp = layout2.getText().replace("\n", "__NEWLINE__");
        PreviewPrefsTab.this.prefs.remove(JabRefPreferences.PREVIEW_1);
        layout2.setText(
                PreviewPrefsTab.this.prefs.get(JabRefPreferences.PREVIEW_1).replace("__NEWLINE__", "\n"));
        PreviewPrefsTab.this.prefs.put(JabRefPreferences.PREVIEW_1, tmp);
    });

    testButton.addActionListener(e -> {
        PreviewPrefsTab.getTestEntry();
        try {
            PreviewPanel testPanel = new PreviewPanel(null, PreviewPrefsTab.entry, null, layout1.getText());
            testPanel.setPreferredSize(new Dimension(800, 350));
            JOptionPane.showMessageDialog(null, testPanel, Localization.lang("Preview"),
                    JOptionPane.PLAIN_MESSAGE);
        } catch (StringIndexOutOfBoundsException ex) {
            LOGGER.warn("Parsing error.", ex);
            JOptionPane.showMessageDialog(null,
                    Localization.lang("Parsing error") + ": "
                            + Localization.lang("illegal backslash expression") + ".\n" + ex.getMessage(),
                    Localization.lang("Parsing error"), JOptionPane.ERROR_MESSAGE);
        }
    });

    testButton2.addActionListener(e -> {
        PreviewPrefsTab.getTestEntry();
        try {
            PreviewPanel testPanel = new PreviewPanel(null, PreviewPrefsTab.entry, null, layout2.getText());
            testPanel.setPreferredSize(new Dimension(800, 350));
            JOptionPane.showMessageDialog(null, new JScrollPane(testPanel), Localization.lang("Preview"),
                    JOptionPane.PLAIN_MESSAGE);
        } catch (StringIndexOutOfBoundsException ex) {
            LOGGER.warn("Parsing error.", ex);
            JOptionPane.showMessageDialog(null,
                    Localization.lang("Parsing error") + ": "
                            + Localization.lang("illegal backslash expression") + ".\n" + ex.getMessage(),
                    Localization.lang("Parsing error"), JOptionPane.ERROR_MESSAGE);
        }
    });
}

From source file:SimpleAuthenticator.java

protected PasswordAuthentication getPasswordAuthentication() {

    // given a prompt?
    String prompt = getRequestingPrompt();
    if (prompt == null)
        prompt = "Please login...";

    // protocol/* w  w  w .jav a  2s.c  om*/
    String protocol = getRequestingProtocol();
    if (protocol == null)
        protocol = "Unknown protocol";

    // get the host
    String host = null;
    InetAddress inet = getRequestingSite();
    if (inet != null)
        host = inet.getHostName();
    if (host == null)
        host = "Unknown host";

    // port
    String port = "";
    int portnum = getRequestingPort();
    if (portnum != -1)
        port = ", port " + portnum + " ";

    // Build the info string
    String info = "Connecting to " + protocol + " mail service on host " + host + port;

    //JPanel d = new JPanel();
    // XXX - for some reason using a JPanel here causes JOptionPane
    // to display incorrectly, so we workaround the problem using
    // an anonymous JComponent.
    JComponent d = new JComponent() {
    };

    GridBagLayout gb = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    d.setLayout(gb);
    c.insets = new Insets(2, 2, 2, 2);

    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 0.0;
    d.add(constrain(new JLabel(info), gb, c));
    d.add(constrain(new JLabel(prompt), gb, c));

    c.gridwidth = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    d.add(constrain(new JLabel("Username:"), gb, c));

    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;
    String user = getDefaultUserName();
    JTextField username = new JTextField(user, 20);
    d.add(constrain(username, gb, c));

    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;
    c.weightx = 0.0;
    d.add(constrain(new JLabel("Password:"), gb, c));

    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;
    JPasswordField password = new JPasswordField("", 20);
    d.add(constrain(password, gb, c));
    // XXX - following doesn't work
    if (user != null && user.length() > 0)
        password.requestFocus();
    else
        username.requestFocus();

    int result = JOptionPane.showConfirmDialog(frame, d, "Login", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);

    if (result == JOptionPane.OK_OPTION)
        return new PasswordAuthentication(username.getText(), password.getText());
    else
        return null;
}

From source file:savant.plugin.ToolSettingsPanel.java

ToolSettingsPanel(Tool t) {
    tool = t;/*from w ww  .  ja  va  2s .  c om*/
    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.gridy = 0;
    try {
        tool.parseDescriptor();
        commandLine = new JLabel("", SwingConstants.CENTER);
        commandLine.setFont(new Font("Serif", Font.PLAIN, 14));
        commandLine.setBorder(
                BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
                        BorderFactory.createEmptyBorder(5, 5, 5, 5)));
        gbc.insets = new Insets(10, 10, 10, 10);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        add(commandLine, gbc);

        JButton executeButton = new JButton("Execute");
        executeButton.addActionListener(executeListener);
        gbc.insets = new Insets(5, 5, 5, 5);
        gbc.gridy = 1;
        gbc.fill = GridBagConstraints.NONE;
        add(executeButton, gbc);

        for (ToolArgument a : tool.arguments) {
            addArgumentToPanel(a, ++gbc.gridy);
        }
        gbc.gridx = 0;
        gbc.gridy++;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        add(new JPanel(), gbc);

        tool.displayCommandLine(commandLine);
    } catch (Exception x) {
        Tool.LOG.info(String.format("Unable to load %s.", tool.getDescriptor().getFile()), x);
        add(new JLabel(String.format("<html>Unable to load <i>%s</i><br>%s</html>",
                tool.getDescriptor().getFile(), x)), gbc);
    }
}

From source file:org.pentaho.ui.xul.swing.tags.SwingGrid.java

@Override
public void layout() {

    if (this.getChildNodes().size() < 2) {
        logger.warn("Grid does not contain Column and Row children");
        return;/*from  ww  w.  j  a  va2 s .c  om*/
    }

    XulComponent columns = this.getChildNodes().get(0);
    XulComponent rows = this.getChildNodes().get(1);

    int colCount = 0;
    int rowCount = 0;
    float colFlexTotal = 0;
    float rowTotalFlex = 0;
    for (XulComponent col : columns.getChildNodes()) {
        if (col.getFlex() > 0) {
            colFlexTotal += col.getFlex();
        }
        colCount++;
    }

    for (XulComponent row : rows.getChildNodes()) {
        if (row.getFlex() > 0) {
            rowTotalFlex += row.getFlex();
        }
        rowCount++;
    }

    for (XulComponent row : rows.getChildNodes()) {
        gc.gridx = 0;

        for (XulComponent xulComp : row.getChildNodes()) {
            gc.weightx = 0.0;
            gc.gridwidth = 1;
            gc.gridheight = 1;
            gc.weighty = 0.0;
            gc.anchor = GridBagConstraints.NORTHWEST;
            gc.fill = GridBagConstraints.NONE;

            Component comp = (Component) xulComp.getManagedObject();
            float colFlex = columns.getChildNodes().get(gc.gridx).getFlex();
            int rowFlex = row.getFlex();

            Align colAlignment = null;
            Align rowAlignment = null;
            String colAlignmentStr = xulComp.getAlign();
            String rowAlignStr = row.getAlign();
            if (colAlignmentStr != null) {
                colAlignment = Align.valueOf(colAlignmentStr);
            }
            if (rowAlignStr != null) {
                rowAlignment = Align.valueOf(rowAlignStr);
            }

            if (colFlex > 0) {
                gc.weightx = (colFlex / colFlexTotal);
            }
            if (rowFlex > 0) {
                gc.weighty = (rowFlex / rowTotalFlex);
            }
            if (colAlignment == Align.STRETCH && xulComp.getFlex() > 0) {
                gc.fill = GridBagConstraints.BOTH;
            } else if (colAlignment == Align.STRETCH) {
                gc.fill = GridBagConstraints.HORIZONTAL;
            } else if (xulComp.getFlex() > 0) {
                gc.fill = GridBagConstraints.VERTICAL;
            }

            if (row.getChildNodes().indexOf(xulComp) + 1 == row.getChildNodes().size()) {
                gc.gridwidth = GridBagConstraints.REMAINDER;
            } else {
                gc.gridwidth = 1;
            }
            if (rows.getChildNodes().indexOf(row) + 1 == rows.getChildNodes().size()) {
                gc.gridheight = GridBagConstraints.REMAINDER;
            } else {
                gc.gridheight = 1;
            }

            // gc.gridheight = row.getFlex() + 1;

            if (colAlignment != null && rowAlignment != null) {
                switch (rowAlignment) {
                case START:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.NORTHWEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.NORTH;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.NORTHEAST;
                        break;
                    }
                    break;
                case CENTER:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.WEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.CENTER;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.EAST;
                        break;
                    }
                    break;
                case END:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.SOUTHWEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.SOUTH;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.SOUTHEAST;
                        break;
                    }
                }
            } else if (rowAlignment != null) {
                switch (rowAlignment) {
                case START:
                    gc.anchor = GridBagConstraints.NORTHWEST;
                    break;
                case CENTER:
                    gc.anchor = GridBagConstraints.WEST;
                    break;
                case END:
                    gc.anchor = GridBagConstraints.SOUTHWEST;
                    break;
                }
            } else if (colAlignment != null) {

                switch (colAlignment) {
                case START:
                    gc.anchor = GridBagConstraints.NORTHWEST;
                    break;
                case CENTER:
                    gc.anchor = GridBagConstraints.NORTH;
                    break;
                case END:
                    gc.anchor = GridBagConstraints.NORTHEAST;
                    break;
                }
            }

            if (comp.getWidth() > 0 || comp.getHeight() > 0) {
                Dimension minSize = comp.getMinimumSize();
                Dimension prefSize = comp.getPreferredSize();

                if (comp.getWidth() > 0) {
                    minSize.width = comp.getWidth();
                    prefSize.width = comp.getWidth();
                }
                if (comp.getHeight() > 0) {
                    minSize.height = comp.getHeight();
                    prefSize.height = comp.getHeight();
                }
                comp.setMinimumSize(minSize);
                comp.setPreferredSize(prefSize);
            } else {
                comp.setPreferredSize(comp.getMinimumSize());
            }

            grid.add(comp, gc);
            gc.gridx++;
        }

        gc.gridy++;
    }

    if (rowTotalFlex == 0) {
        // Add in an extra row at the bottom to push others up
        gc.gridy++;
        gc.weighty = 1;
        gc.fill = gc.REMAINDER;
        grid.add(Box.createGlue(), gc);
    }
    this.initialized = true;
}

From source file:MessageViewer.java

protected void addToolbar() {
    GridBagConstraints gb = new GridBagConstraints();
    gb.gridheight = 1;// ww  w  . j a va 2  s  .c  om
    gb.gridwidth = 1;
    gb.fill = GridBagConstraints.NONE;
    gb.anchor = GridBagConstraints.WEST;
    gb.weightx = 0.0;
    gb.weighty = 0.0;
    gb.insets = new Insets(4, 4, 4, 4);

    // structure button
    gb.gridwidth = GridBagConstraints.REMAINDER; // only for the last one
    Button b = new Button("Structure");
    b.addActionListener(new StructureAction());
    add(b, gb);
}