Example usage for java.awt GridBagLayout setConstraints

List of usage examples for java.awt GridBagLayout setConstraints

Introduction

In this page you can find the example usage for java.awt GridBagLayout setConstraints.

Prototype

public void setConstraints(Component comp, GridBagConstraints constraints) 

Source Link

Document

Sets the constraints for the specified component in this layout.

Usage

From source file:cool.pandora.modeller.ui.jpanel.text.PatchAreasFrame.java

private JPanel createComponents() {
    final Border border = new EmptyBorder(5, 5, 5, 5);

    final TitlePane titlePane = new TitlePane();
    initStandardCommands();//from www .ja v a2s  .c o m
    final JPanel pageControl = new JPanel(new BorderLayout());
    final JPanel titlePaneContainer = new JPanel(new BorderLayout());
    titlePane.setTitle(bagView.getPropertyMessage("PatchAreasFrame.title"));
    titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Patch Areas in:")));
    titlePaneContainer.add(titlePane.getControl());
    titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
    pageControl.add(titlePaneContainer, BorderLayout.NORTH);
    final JPanel contentPane = new JPanel();

    final DefaultBag bag = bagView.getBag();
    if (bag != null) {
        map = bag.getInfo().getFieldMap();
    }

    final JLabel urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label"));
    urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description"));
    final JTextField urlField = new JTextField("");
    final URI uri = TextObjectURI.getAreaContainerURI(map);
    try {
        assert uri != null;
        urlField.setText(uri.toString());
    } catch (Exception e) {
        log.error("Failed to set url label", e);
    }

    final JLabel hocrResourceLabel = new JLabel(bagView.getPropertyMessage("hocrResource" + ".label"));
    hocrResourceLabel.setToolTipText(bagView.getPropertyMessage("hocrResource.description"));
    hocrResourceField = new JTextField("");
    final String hocrResource = TextObjectURI.gethOCRResourceURI(map);
    try {
        hocrResourceField.setText(hocrResource);
    } catch (Exception e) {
        log.error("Failed to set hocrResource label", e);
    }

    final GridBagLayout layout = new GridBagLayout();
    final GridBagConstraints glbc = new GridBagConstraints();
    final JPanel panel = new JPanel(layout);
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));

    int row = 0;

    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(urlLabel, glbc);
    panel.add(urlLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(urlField, glbc);
    panel.add(urlField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(hocrResourceLabel, glbc);
    panel.add(hocrResourceLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(hocrResourceField, glbc);
    panel.add(hocrResourceField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);

    GuiStandardUtils.attachDialogBorder(contentPane);
    pageControl.add(panel);
    final JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;

}

From source file:cool.pandora.modeller.ui.jpanel.text.PatchLinesFrame.java

private JPanel createComponents() {
    final Border border = new EmptyBorder(5, 5, 5, 5);

    final TitlePane titlePane = new TitlePane();
    initStandardCommands();/*from   w  w  w  . jav  a2s  .  co  m*/
    final JPanel pageControl = new JPanel(new BorderLayout());
    final JPanel titlePaneContainer = new JPanel(new BorderLayout());
    titlePane.setTitle(bagView.getPropertyMessage("PatchLinesFrame.title"));
    titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Patch Lines in:")));
    titlePaneContainer.add(titlePane.getControl());
    titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
    pageControl.add(titlePaneContainer, BorderLayout.NORTH);
    final JPanel contentPane = new JPanel();

    final DefaultBag bag = bagView.getBag();
    if (bag != null) {
        map = bag.getInfo().getFieldMap();
    }

    final JLabel urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label"));
    urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description"));
    final JTextField urlField = new JTextField("");
    final URI uri = TextObjectURI.getLineContainerURI(map);
    try {
        assert uri != null;
        urlField.setText(uri.toString());
    } catch (Exception e) {
        log.error("Failed to set url label", e);
    }

    final JLabel hocrResourceLabel = new JLabel(bagView.getPropertyMessage("hocrResource" + ".label"));
    hocrResourceLabel.setToolTipText(bagView.getPropertyMessage("hocrResource.description"));
    hocrResourceField = new JTextField("");
    final String hocrResource = TextObjectURI.gethOCRResourceURI(map);
    try {
        hocrResourceField.setText(hocrResource);
    } catch (Exception e) {
        log.error("Failed to set hocrResource label", e);
    }

    final GridBagLayout layout = new GridBagLayout();
    final GridBagConstraints glbc = new GridBagConstraints();
    final JPanel panel = new JPanel(layout);
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));

    int row = 0;

    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(urlLabel, glbc);
    panel.add(urlLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(urlField, glbc);
    panel.add(urlField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(hocrResourceLabel, glbc);
    panel.add(hocrResourceLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(hocrResourceField, glbc);
    panel.add(hocrResourceField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);

    GuiStandardUtils.attachDialogBorder(contentPane);
    pageControl.add(panel);
    final JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;

}

From source file:cool.pandora.modeller.ui.jpanel.text.PatchPagesFrame.java

private JPanel createComponents() {
    final Border border = new EmptyBorder(5, 5, 5, 5);

    final TitlePane titlePane = new TitlePane();
    initStandardCommands();//  ww  w  .j  av a 2  s  .c  o m
    final JPanel pageControl = new JPanel(new BorderLayout());
    final JPanel titlePaneContainer = new JPanel(new BorderLayout());
    titlePane.setTitle(bagView.getPropertyMessage("PatchPagesFrame.title"));
    titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Patch Pages in:")));
    titlePaneContainer.add(titlePane.getControl());
    titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
    pageControl.add(titlePaneContainer, BorderLayout.NORTH);
    final JPanel contentPane = new JPanel();

    final DefaultBag bag = bagView.getBag();
    if (bag != null) {
        map = bag.getInfo().getFieldMap();
    }

    final JLabel urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label"));
    urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description"));
    final JTextField urlField = new JTextField("");
    final URI uri = TextObjectURI.getPageContainerURI(map);
    try {
        assert uri != null;
        urlField.setText(uri.toString());
    } catch (Exception e) {
        log.error("Failed to set url label", e);
    }

    final JLabel hocrResourceLabel = new JLabel(bagView.getPropertyMessage("hocrResource" + ".label"));
    hocrResourceLabel.setToolTipText(bagView.getPropertyMessage("hocrResource.description"));
    hocrResourceField = new JTextField("");
    final String hocrResource = TextObjectURI.gethOCRResourceURI(map);
    try {
        hocrResourceField.setText(hocrResource);
    } catch (Exception e) {
        log.error("Failed to set hocrResource label", e);
    }

    final GridBagLayout layout = new GridBagLayout();
    final GridBagConstraints glbc = new GridBagConstraints();
    final JPanel panel = new JPanel(layout);
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));

    int row = 0;

    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(urlLabel, glbc);
    panel.add(urlLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(urlField, glbc);
    panel.add(urlField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(hocrResourceLabel, glbc);
    panel.add(hocrResourceLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(hocrResourceField, glbc);
    panel.add(hocrResourceField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);

    GuiStandardUtils.attachDialogBorder(contentPane);
    pageControl.add(panel);
    final JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;

}

From source file:cool.pandora.modeller.ui.jpanel.text.PatchWordsFrame.java

private JPanel createComponents() {
    final Border border = new EmptyBorder(5, 5, 5, 5);

    final TitlePane titlePane = new TitlePane();
    initStandardCommands();/*from w w w  .ja  v  a2s  .  c o m*/
    final JPanel pageControl = new JPanel(new BorderLayout());
    final JPanel titlePaneContainer = new JPanel(new BorderLayout());
    titlePane.setTitle(bagView.getPropertyMessage("PatchWordsFrame.title"));
    titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Patch Words in:")));
    titlePaneContainer.add(titlePane.getControl());
    titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
    pageControl.add(titlePaneContainer, BorderLayout.NORTH);
    final JPanel contentPane = new JPanel();

    final DefaultBag bag = bagView.getBag();
    if (bag != null) {
        map = bag.getInfo().getFieldMap();
    }

    final JLabel urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label"));
    urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description"));
    final JTextField urlField = new JTextField("");
    final URI uri = TextObjectURI.getWordContainerURI(map);
    try {
        assert uri != null;
        urlField.setText(uri.toString());
    } catch (Exception e) {
        log.error("Failed to set url label", e);
    }

    final JLabel hocrResourceLabel = new JLabel(bagView.getPropertyMessage("hocrResource" + ".label"));
    hocrResourceLabel.setToolTipText(bagView.getPropertyMessage("hocrResource.description"));
    hocrResourceField = new JTextField("");
    final String hocrResource = TextObjectURI.gethOCRResourceURI(map);
    try {
        hocrResourceField.setText(hocrResource);
    } catch (Exception e) {
        log.error("Failed to set hocrResource label", e);
    }

    final GridBagLayout layout = new GridBagLayout();
    final GridBagConstraints glbc = new GridBagConstraints();
    final JPanel panel = new JPanel(layout);
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));

    int row = 0;

    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(urlLabel, glbc);
    panel.add(urlLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(urlField, glbc);
    panel.add(urlField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(hocrResourceLabel, glbc);
    panel.add(hocrResourceLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(hocrResourceField, glbc);
    panel.add(hocrResourceField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);

    GuiStandardUtils.attachDialogBorder(contentPane);
    pageControl.add(panel);
    final JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;

}

From source file:Composite.java

public void init() {
    GridBagLayout layOut = new GridBagLayout();
    getContentPane().setLayout(layOut);//from   www . j  av  a  2  s .c  o m

    GridBagConstraints l = new GridBagConstraints();
    l.weightx = 1.0;
    l.fill = GridBagConstraints.BOTH;
    l.gridwidth = GridBagConstraints.RELATIVE;
    alphaLabel = new JLabel();
    alphaLabel.setText("Alphas");
    Font newFont = getFont().deriveFont(1);
    alphaLabel.setFont(newFont);
    alphaLabel.setHorizontalAlignment(JLabel.CENTER);
    layOut.setConstraints(alphaLabel, l);
    getContentPane().add(alphaLabel);
    GridBagConstraints c = new GridBagConstraints();
    getContentPane().setLayout(layOut);

    l.gridwidth = GridBagConstraints.REMAINDER;
    rulesLabel = new JLabel();
    rulesLabel.setText("Rules");
    newFont = getFont().deriveFont(1);
    rulesLabel.setFont(newFont);
    rulesLabel.setHorizontalAlignment(JLabel.CENTER);
    layOut.setConstraints(rulesLabel, l);
    getContentPane().add(rulesLabel);

    GridBagConstraints a = new GridBagConstraints();
    a.gridwidth = GridBagConstraints.RELATIVE;
    a.weightx = 1.0;
    a.fill = GridBagConstraints.BOTH;
    alphas = new JComboBox();
    layOut.setConstraints(alphas, a);
    alphas.addItem("1.0");
    alphas.addItem("0.75");
    alphas.addItem("0.50");
    alphas.addItem("0.25");
    alphas.addItem("0.0");
    alphas.addItemListener(this);
    getContentPane().add(alphas);

    a.gridwidth = GridBagConstraints.REMAINDER;
    rules = new JComboBox();
    layOut.setConstraints(rules, a);
    rules.addItem("SRC");
    rules.addItem("DST_IN");
    rules.addItem("DST_OUT");
    rules.addItem("DST_OVER");
    rules.addItem("SRC_IN");
    rules.addItem("SRC_OVER");
    rules.addItem("SRC_OUT");
    rules.addItem("CLEAR");
    rules.addItemListener(this);
    getContentPane().add(rules);

    GridBagConstraints fC = new GridBagConstraints();
    fC.fill = GridBagConstraints.BOTH;
    fC.weightx = 1.0;
    fC.weighty = 1.0;
    fC.gridwidth = GridBagConstraints.REMAINDER;
    comp = new CompPanel();
    layOut.setConstraints(comp, fC);
    getContentPane().add(comp);

    validate();
}

From source file:it.cnr.icar.eric.client.ui.swing.DiscoveryPanel.java

/**
 * Class Constructor./*ww w . ja v  a 2 s.  com*/
 */
public DiscoveryPanel() throws JAXRException {
    GridBagLayout gbl = new GridBagLayout();
    setLayout(gbl);

    findParamsPanel = new FindParamsPanel(this);

    JPanel findResultsPanel = createFindResultsPanel();

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, findParamsPanel, findResultsPanel);
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 0.5;
    c.weighty = 0.5;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(4, 4, 4, 4);
    gbl.setConstraints(splitPane, c);
    add(splitPane);

    //add listener for 'locale' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this);
}

From source file:org.wsm.database.tools.editor.ui.GraphPane.java

public GraphPane() {
    GridBagLayout gbl = new GridBagLayout();
    this.setLayout(gbl);

    this.qesi = new QueryExecStatsInfo();
    this.qesi.addPropertyChangeListener(this);
    dcd = new DefaultCategoryDataset();
    JFreeChart chart = getChart(CHART_TYPE_BAR_3D);

    chart.setBackgroundPaint(Color.white);

    cp = new ChartPanel(chart);
    cp.setBorder(BorderFactory.createTitledBorder(null, "Graph", TitledBorder.LEADING, TitledBorder.TOP,
            UIConstants.LABEL_FONT));//  w w  w  .  j a  v  a 2 s.  co m

    cp.setMouseZoomable(true, true);
    //cp.setPreferredSize(new Dimension(700, 500));
    gbl.setConstraints(cp, SwingUtils.getGridBagConstraints(0, 0, 2, 1));

    this.add(cp);
    JPanel graphTypeSelectionPanel = new JPanel();
    viewBarGraph = new JRadioButton("View Bar Graph", true);
    viewLineGraph = new JRadioButton("View Line Graph", false);
    viewLineGraph.setEnabled(false);
    ButtonGroup bg = new ButtonGroup();
    bg.add(viewBarGraph);
    bg.add(viewLineGraph);

    GridBagLayout graphTypeGBL = new GridBagLayout();
    graphTypeSelectionPanel.setLayout(graphTypeGBL);

    graphTypeGBL.setConstraints(viewBarGraph, SwingUtils.getGridBagConstraints(0, 0));
    graphTypeGBL.setConstraints(viewLineGraph, SwingUtils.getGridBagConstraints(1, 0));
    graphTypeSelectionPanel.add(viewBarGraph);
    graphTypeSelectionPanel.add(viewLineGraph);
    viewBarGraph.addActionListener(this);
    viewLineGraph.addActionListener(this);

    graphTypeSelectionPanel.setBorder(BorderFactory.createTitledBorder(null, "Graph Type", TitledBorder.LEADING,
            TitledBorder.TOP, UIConstants.LABEL_FONT));

    gbl.setConstraints(graphTypeSelectionPanel, SwingUtils.getGridBagConstraints(0, 1, 2, 1));

    this.add(graphTypeSelectionPanel);
    //this.setBounds(50, 100, 100, 200);
    this.setBackground(Color.WHITE);
}

From source file:it.cnr.icar.eric.client.ui.swing.FindParamsPanel.java

/**
 * Class Constructor./*from w w w.ja v  a 2s. c o  m*/
 */
public FindParamsPanel(DiscoveryPanel discoveryPanel) throws JAXRException {
    this.discoveryPanel = discoveryPanel;

    GridBagLayout gbl = new GridBagLayout();
    setLayout(gbl);

    //The searchTypeSelectionPanel at the top of the panel
    JPanel searchTypePanel = createSearchTypePanel();
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 0.0;
    c.weighty = 0.0;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTH;
    c.insets = new Insets(4, 4, 0, 4);
    gbl.setConstraints(searchTypePanel, c);
    add(searchTypePanel);

    //The federated CheckBox
    federatedCheckBox = new JCheckBox(resourceBundle.getString("label.federatedQuery"));
    federatedCheckBox.setSelected(false);
    federatedCheckBox.setEnabled(true);
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 0.0;
    c.weighty = 0.0;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTH;
    c.insets = new Insets(4, 4, 0, 4);
    gbl.setConstraints(federatedCheckBox, c);
    add(federatedCheckBox);

    //The actionPanel
    JPanel actionPanel = createActionPanel();
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 0.0;
    c.weighty = 0.0;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTH;
    c.insets = new Insets(4, 4, 0, 4);
    gbl.setConstraints(searchTypePanel, c);
    add(actionPanel);

    //Next is the panel that is the parent of both adhocQueryPanel and
    //businessQueryPanel
    paramEntryParentPanel = createParamEntryParentPanel();
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 0.5;
    c.weighty = 0.5;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.NORTH;
    c.insets = new Insets(4, 4, 0, 4);
    gbl.setConstraints(paramEntryParentPanel, c);
    add(paramEntryParentPanel);

    //RegistryBrowser.getInstance().getConceptsTreeDialog().addPropertyChangeListener(this);
    //add listener for 'locale' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this);
}

From source file:IconDemoApplet.java

public void init() {
    //Parse the applet parameters
    pictures = parseParameters();/*from w w  w.  j  av  a 2s  .com*/

    //If the applet tag doesn't provide an "IMAGE0" parameter,
    //display an error message.
    if (pictures.size() == 0) {
        captionLabel = new JLabel("No images listed in applet tag.");
        captionLabel.setHorizontalAlignment(JLabel.CENTER);
        getContentPane().add(captionLabel);
        return;
    }

    //NOW CREATE THE GUI COMPONENTS

    //A label to identify XX of XX.
    numberLabel = new JLabel("Picture " + (current + 1) + " of " + pictures.size());
    numberLabel.setHorizontalAlignment(JLabel.LEFT);
    numberLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 5));

    //A label for the caption.
    final Photo first = (Photo) pictures.firstElement();
    captionLabel = new JLabel(first.caption);
    captionLabel.setHorizontalAlignment(JLabel.CENTER);
    captionLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));

    //A label for displaying the photographs.
    photographLabel = new JLabel("Loading first image...");
    photographLabel.setHorizontalAlignment(JLabel.CENTER);
    photographLabel.setVerticalAlignment(JLabel.CENTER);
    photographLabel.setVerticalTextPosition(JLabel.CENTER);
    photographLabel.setHorizontalTextPosition(JLabel.CENTER);
    photographLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    photographLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0),
            photographLabel.getBorder()));

    //Set the preferred size for the picture,
    //with room for the borders.
    Insets i = photographLabel.getInsets();
    photographLabel.setPreferredSize(
            new Dimension(widthOfWidest + i.left + i.right, heightOfTallest + i.bottom + i.top));

    //Create the next and previous buttons.
    ImageIcon nextIcon = new ImageIcon(getURL(imagedir + "right.gif"));
    ImageIcon dimmedNextIcon = new ImageIcon(getURL(imagedir + "dimmedRight.gif"));
    ImageIcon previousIcon = new ImageIcon(getURL(imagedir + "left.gif"));
    ImageIcon dimmedPreviousIcon = new ImageIcon(getURL(imagedir + "dimmedLeft.gif"));

    previousButton = new JButton("Previous Picture", previousIcon);
    previousButton.setDisabledIcon(dimmedPreviousIcon);
    previousButton.setVerticalTextPosition(AbstractButton.CENTER);
    previousButton.setHorizontalTextPosition(AbstractButton.RIGHT);
    previousButton.setMnemonic(KeyEvent.VK_P);
    previousButton.setActionCommand("previous");
    previousButton.addActionListener(this);
    previousButton.setEnabled(false);

    nextButton = new JButton("Next Picture", nextIcon);
    nextButton.setDisabledIcon(dimmedNextIcon);
    nextButton.setVerticalTextPosition(AbstractButton.CENTER);
    nextButton.setHorizontalTextPosition(AbstractButton.LEFT);
    nextButton.setMnemonic(KeyEvent.VK_N);
    nextButton.setActionCommand("next");
    nextButton.addActionListener(this);

    //Lay out the GUI.
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    Container contentPane = getContentPane();
    contentPane.setLayout(layout);

    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    layout.setConstraints(numberLabel, c);
    contentPane.add(numberLabel);

    layout.setConstraints(captionLabel, c);
    contentPane.add(captionLabel);

    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.BOTH;
    layout.setConstraints(photographLabel, c);
    contentPane.add(photographLabel);

    c.gridwidth = GridBagConstraints.RELATIVE;
    c.fill = GridBagConstraints.HORIZONTAL;
    layout.setConstraints(previousButton, c);
    contentPane.add(previousButton);

    c.gridwidth = GridBagConstraints.REMAINDER;
    layout.setConstraints(nextButton, c);
    contentPane.add(nextButton);

    //Start loading the image for the first photograph now.
    //The loadImage method uses a SwingWorker
    //to load the image in a separate thread.
    loadImage(imagedir + first.filename, current);
}

From source file:GetOpenProperties.java

public void init() {
    //Set up the layout.
    GridBagLayout gridbag = new GridBagLayout();
    setLayout(gridbag);//from www.  j  a  v a  2s .co  m
    GridBagConstraints labelConstraints = new GridBagConstraints();
    GridBagConstraints valueConstraints = new GridBagConstraints();
    labelConstraints.anchor = GridBagConstraints.WEST;
    labelConstraints.ipadx = 10;
    valueConstraints.fill = GridBagConstraints.HORIZONTAL;
    valueConstraints.gridwidth = GridBagConstraints.REMAINDER;
    valueConstraints.weightx = 1.0; //Extra space to values column.

    //Set up the Label arrays.
    Label[] names = new Label[numProperties];
    values = new Label[numProperties];
    String firstValue = "not read yet";

    for (int i = 0; i < numProperties; i++) {
        names[i] = new Label(propertyNames[i]);
        gridbag.setConstraints(names[i], labelConstraints);
        add(names[i]);

        values[i] = new Label(firstValue);
        gridbag.setConstraints(values[i], valueConstraints);
        add(values[i]);
    }

    new Thread(this, "Loading System Properties").start();
}