Example usage for java.awt GridBagConstraints CENTER

List of usage examples for java.awt GridBagConstraints CENTER

Introduction

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

Prototype

int CENTER

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

Click Source Link

Document

Put the component in the center of its display area.

Usage

From source file:com.sec.ose.osi.ui.frm.main.report.JPanExportReport.java

private JPanel getJPanelForReportTypeInfo() {
    if (jPanelForReportTypeInfo == null) {
        GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
        gridBagConstraints5.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints5.gridx = -1;//from   ww w .j  av a 2s  .c o  m
        gridBagConstraints5.gridy = -1;
        gridBagConstraints5.gridwidth = 1;
        gridBagConstraints5.anchor = GridBagConstraints.CENTER;
        gridBagConstraints5.weightx = 1.0;
        gridBagConstraints5.weighty = 0.0;
        gridBagConstraints5.insets = new Insets(0, 10, 5, 150); // margin // top, left, bottom, right
        jPanelForReportTypeInfo = new JPanel();
        jPanelForReportTypeInfo.setLayout(new GridBagLayout());
        jPanelForReportTypeInfo.setBorder(BorderFactory.createTitledBorder(null, "Report Type",
                TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
                new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
        jPanelForReportTypeInfo.add(getJPanelReportTypeInfo(), gridBagConstraints5);
    }
    return jPanelForReportTypeInfo;
}

From source file:com.stefanbrenner.droplet.utils.UiUtilsTest.java

@Test
public void testEditGridBagConstraints() {
    GridBagConstraints gbc = new GridBagConstraints(1, 2, 3, 4, 5.0, 6.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(1, 2, 3, 4), 9, 0);

    UiUtils.editGridBagConstraints(gbc, 11, 12);
    assertEquals(11, gbc.gridx);//from  ww  w.  j  av a 2 s  .  co m
    assertEquals(12, gbc.gridy);
    assertEquals(3, gbc.gridwidth);
    assertEquals(4, gbc.gridheight);
    assertEquals(0.0, gbc.weightx);
    assertEquals(0.0, gbc.weighty);
    assertEquals(GridBagConstraints.CENTER, gbc.anchor);
    assertEquals(GridBagConstraints.BOTH, gbc.fill);

    UiUtils.editGridBagConstraints(gbc, 13, 14, 15.0, 16.0);
    assertEquals(13, gbc.gridx);
    assertEquals(14, gbc.gridy);
    assertEquals(3, gbc.gridwidth);
    assertEquals(4, gbc.gridheight);
    assertEquals(15.0, gbc.weightx);
    assertEquals(16.0, gbc.weighty);
    assertEquals(GridBagConstraints.CENTER, gbc.anchor);
    assertEquals(GridBagConstraints.BOTH, gbc.fill);

    UiUtils.editGridBagConstraints(gbc, 17, 18, 19.0, 20.0, GridBagConstraints.WEST);
    assertEquals(17, gbc.gridx);
    assertEquals(18, gbc.gridy);
    assertEquals(3, gbc.gridwidth);
    assertEquals(4, gbc.gridheight);
    assertEquals(19.0, gbc.weightx);
    assertEquals(20.0, gbc.weighty);
    assertEquals(GridBagConstraints.WEST, gbc.anchor);
    assertEquals(GridBagConstraints.BOTH, gbc.fill);

}

From source file:net.sourceforge.processdash.ev.ui.ScheduleBalancingDialog.java

private void addButtons(JDialog dialog, JPanel panel, int gridY) {
    Box buttonBox = BoxUtils.hbox( //
            new JButton(new OKAction(dialog)), 5, //
            new JButton(new RevertTimesAction()), 5, //
            new JButton(new CancelAction(dialog)));

    GridBagConstraints c = new GridBagConstraints();
    c.gridy = gridY;//from w w w. j a va 2s .  c  om
    c.gridwidth = 4;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(10, 10, 0, 10);
    panel.add(buttonBox, c);
}

From source file:com.vgi.mafscaling.VECalc.java

protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false,
            true, false);/*from   w w w.j av a2s. c  o m*/
    chart.setBorderVisible(true);

    chartPanel = new ChartPanel(chart, true, true, true, true, true);
    chartPanel.setAutoscrolls(true);
    chartPanel.setMouseZoomable(false);

    GridBagConstraints gbl_chartPanel = new GridBagConstraints();
    gbl_chartPanel.anchor = GridBagConstraints.CENTER;
    gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
    gbl_chartPanel.weightx = 1.0;
    gbl_chartPanel.weighty = 1.0;
    gbl_chartPanel.fill = GridBagConstraints.BOTH;
    gbl_chartPanel.gridx = 0;
    gbl_chartPanel.gridy = 1;
    plotPanel.add(chartPanel, gbl_chartPanel);

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
    lineRenderer.setUseFillPaint(true);
    lineRenderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new DecimalFormat("0.00"), new DecimalFormat("0.00")));

    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
    lineRenderer.setSeriesStroke(0, stroke);
    lineRenderer.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));

    lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
        private static final long serialVersionUID = 7593430826693873496L;

        public String generateLabel(XYDataset dataset, int series) {
            XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
            return xys.getDescription();
        }
    });

    NumberAxis xAxis = new NumberAxis(xAxisName);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisName);
    yAxis.setAutoRangeIncludesZero(false);

    XYSeriesCollection lineDataset = new XYSeriesCollection();

    XYPlot plot = chart.getXYPlot();
    plot.setRangePannable(true);
    plot.setDomainPannable(true);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.setBackgroundPaint(new Color(224, 224, 224));

    plot.setDataset(0, lineDataset);
    plot.setRenderer(0, lineRenderer);
    plot.setDomainAxis(0, xAxis);
    plot.setRangeAxis(0, yAxis);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    LegendTitle legend = new LegendTitle(plot.getRenderer());
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    chart.addLegend(legend);
}

From source file:org.archiviststoolkit.plugin.utils.CodeViewerDialog.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner non-commercial license
    dialogPane = new JPanel();
    contentPanel = new JPanel();
    scrollPane1 = new JScrollPane();
    messageTextArea = new JTextArea();
    buttonBar = new JPanel();
    recordTestPanel = new JPanel();
    storeButton = new JButton();
    testButton = new JButton();
    label1 = new JLabel();
    testHostUrlTextField = new JTextField();
    deleteButton = new JButton();
    okButton = new JButton();
    CellConstraints cc = new CellConstraints();

    //======== this ========
    setTitle("Code Viewer");
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    //======== dialogPane ========
    {//from w  w w . j a va2 s.  c  om
        dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
        dialogPane.setLayout(new BorderLayout());

        //======== contentPanel ========
        {
            contentPanel.setLayout(new BorderLayout());

            //======== scrollPane1 ========
            {

                //---- messageTextArea ----
                messageTextArea.setRows(4);
                messageTextArea.setEditable(false);
                scrollPane1.setViewportView(messageTextArea);
            }
            contentPanel.add(scrollPane1, BorderLayout.SOUTH);
        }
        dialogPane.add(contentPanel, BorderLayout.CENTER);

        //======== buttonBar ========
        {
            buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
            buttonBar.setLayout(new GridBagLayout());
            ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] { 0, 80 };
            ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] { 1.0, 0.0 };

            //======== recordTestPanel ========
            {
                recordTestPanel.setLayout(new FormLayout(
                        new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC, FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                                FormFactory.DEFAULT_COLSPEC, FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                                FormFactory.DEFAULT_COLSPEC, FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                                new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW),
                                FormFactory.LABEL_COMPONENT_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC },
                        RowSpec.decodeSpecs("default")));

                //---- storeButton ----
                storeButton.setText("Store");
                storeButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        storeButtonActionPerformed();
                    }
                });
                recordTestPanel.add(storeButton, cc.xy(1, 1));

                //---- testButton ----
                testButton.setText("Test");
                testButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        testButtonActionPerformed();
                    }
                });
                recordTestPanel.add(testButton, cc.xy(3, 1));

                //---- label1 ----
                label1.setText("Url");
                recordTestPanel.add(label1, cc.xy(5, 1));
                recordTestPanel.add(testHostUrlTextField, cc.xy(7, 1));

                //---- deleteButton ----
                deleteButton.setText("Delete");
                deleteButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        deleteButtonActionPerformed();
                    }
                });
                recordTestPanel.add(deleteButton, cc.xy(9, 1));
            }
            buttonBar.add(recordTestPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0));

            //---- okButton ----
            okButton.setText("OK");
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    okButtonActionPerformed();
                }
            });
            buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        }
        dialogPane.add(buttonBar, BorderLayout.SOUTH);
    }
    contentPane.add(dialogPane, BorderLayout.CENTER);
    pack();
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:cool.pandora.modeller.ui.jpanel.base.NewBagInPlaceFrame.java

/**
 * layoutAddKeepFilesToEmptyCheckBox./*from  w  ww.  j av  a2  s  .  c  o  m*/
 *
 * <p>Setting and displaying the ".keep Files in Empty Folder(s):" Check Box
 * on the Create Bag In Place Pane
 */
private void layoutAddKeepFilesToEmptyCheckBox(final JPanel contentPane, final int row) {
    // Delete Empty Folder(s)
    final JLabel addKeepFilesToEmptyFoldersCheckBoxLabel = new JLabel(
            bagView.getPropertyMessage("bag.label" + ".addkeepfilestoemptyfolders"));
    addKeepFilesToEmptyFoldersCheckBoxLabel
            .setToolTipText(bagView.getPropertyMessage("bag" + ".addkeepfilestoemptyfolders" + ".help"));
    final JCheckBox addKeepFilesToEmptyFoldersCheckBox = new JCheckBox(bagView.getPropertyMessage(""));
    addKeepFilesToEmptyFoldersCheckBox.setSelected(bag.isAddKeepFilesToEmptyFolders());
    addKeepFilesToEmptyFoldersCheckBox.addActionListener(new AddKeepFilesToEmptyFoldersHandler());

    GridBagConstraints glbc = new GridBagConstraints();

    final JLabel spacerLabel = new JLabel();
    glbc = LayoutUtil.buildGridBagConstraints(0, row, 1, 1, 5, 50, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.WEST);
    contentPane.add(addKeepFilesToEmptyFoldersCheckBoxLabel, glbc);
    glbc = LayoutUtil.buildGridBagConstraints(1, row, 1, 1, 40, 50, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.CENTER);
    contentPane.add(addKeepFilesToEmptyFoldersCheckBox, glbc);
    glbc = LayoutUtil.buildGridBagConstraints(2, row, 1, 1, 40, 50, GridBagConstraints.NONE,
            GridBagConstraints.EAST);
    contentPane.add(spacerLabel, glbc);
}

From source file:de.codesourcery.jasm16.ide.ui.views.EmulationOptionsView.java

private JPanel createPanel() {

    final JPanel result = new JPanel();

    result.setLayout(new GridBagLayout());

    // 'Memory protection' checkbox
    int y = 0;/*  w w  w.  jav  a2  s  .c om*/
    GridBagConstraints cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = 2;
    result.add(box1, cnstrs);

    cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = 2;
    result.add(box2, cnstrs);

    cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = 2;
    result.add(box3, cnstrs);

    cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = 2;
    result.add(box8, cnstrs);

    cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = 2;
    result.add(box4, cnstrs);

    cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = 2;
    result.add(box5, cnstrs);

    cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = 2;
    result.add(box6, cnstrs);

    cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = 2;
    result.add(box7, cnstrs);

    cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = 2;
    result.add(diskDrivePanel, cnstrs);

    cnstrs = constraints(0, y++, true, false, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = 2;
    result.add(emulatorPanel, cnstrs);

    // cancel button
    cnstrs = constraints(0, y, false, false, GridBagConstraints.NONE);
    cnstrs.weightx = 0.33;
    cnstrs.anchor = GridBagConstraints.CENTER;

    final JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            onCancel();
        }
    });
    result.add(cancelButton, cnstrs);

    // save button
    cnstrs = constraints(1, y, true, false, GridBagConstraints.NONE);
    cnstrs.weightx = 0.33;
    cnstrs.anchor = GridBagConstraints.CENTER;

    final JButton saveButton = new JButton("Save");
    saveButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final EmulationOptions options = new EmulationOptions();
            saveChangesTo(options);
            onSave(options);
        }

    });
    result.add(saveButton, cnstrs);

    return result;
}

From source file:pcgui.SetupMapVisualizationPanel.java

public void init() {
    setLayout(new BorderLayout());
    JLabel headingLabel = new JLabel("Setup Map Visualization");
    headingLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
    add(headingLabel, BorderLayout.NORTH);

    JLabel mapTypeLabel = new JLabel("Map Type");
    mapTypeLabel.setPreferredSize(new Dimension(140, 30));
    mapTypeLabel.setHorizontalTextPosition(JLabel.CENTER);
    mapTypeCB = new JComboBox<String>(mapTypes);
    mapTypeCB.setPreferredSize(new Dimension(140, 30));

    JLabel sourceLabel = new JLabel("Source");
    sourceLabel.setPreferredSize(new Dimension(140, 30));
    sourceLabel.setHorizontalTextPosition(JLabel.CENTER);
    //      locationsTF = new JTextField();
    //      locationsTF.setPreferredSize(new Dimension(100, 20));
    if (trackedVariables == null) {
        trackedVariables = new ArrayList<String>();
        trackedVariables.add("");
    }//from   w  w  w .  j  a v a  2s. c o m
    locationsCB = new JComboBox<String>(new DefaultComboBoxModel(trackedVariables.toArray()));
    locationsCB.setPreferredSize(new Dimension(140, 30));

    JLabel destLabel = new JLabel("Destination");
    destLabel.setPreferredSize(new Dimension(140, 30));
    destLabel.setHorizontalTextPosition(JLabel.CENTER);
    //      destLocationsTF = new JTextField();
    //      destLocationsTF.setPreferredSize(new Dimension(140, 30));
    destinationsCB = new JComboBox<String>(new DefaultComboBoxModel(trackedVariables.toArray()));
    destinationsCB.setPreferredSize(new Dimension(140, 30));

    JLabel nodeCondLabel = new JLabel("Node condition");
    nodeCondLabel.setPreferredSize(new Dimension(140, 30));
    nodeCondLabel.setHorizontalTextPosition(JLabel.CENTER);
    //      nodeConditionTF = new JTextField();
    //      nodeConditionTF.setPreferredSize(new Dimension(140, 30));
    nodeConditionCB = new JComboBox<String>(new DefaultComboBoxModel(trackedVariables.toArray()));
    nodeConditionCB.setPreferredSize(new Dimension(140, 30));

    JLabel edgeCondLabel = new JLabel("Edge Condition");
    edgeCondLabel.setPreferredSize(new Dimension(140, 30));
    edgeCondLabel.setHorizontalTextPosition(JLabel.CENTER);
    //      edgeConditionTF = new JTextField();
    //      edgeConditionTF.setPreferredSize(new Dimension(140, 30));
    edgeConditionCB = new JComboBox<String>(new DefaultComboBoxModel(trackedVariables.toArray()));
    edgeConditionCB.setPreferredSize(new Dimension(140, 30));

    JLabel showAllLabel = new JLabel("Show All Nodes");
    showAllLabel.setPreferredSize(new Dimension(140, 30));
    showAllLabel.setHorizontalTextPosition(JLabel.CENTER);
    showAllNodes = new JCheckBox("Show All Nodes");
    showAllNodes.setPreferredSize(new Dimension(140, 30));

    JLabel iterationNumLabel = new JLabel("Iteration Number");
    iterationNumLabel.setPreferredSize(new Dimension(140, 30));
    iterationNumLabel.setHorizontalTextPosition(JLabel.CENTER);
    iterationCountTF = new JTextField("1");
    iterationCountTF.setPreferredSize(new Dimension(140, 30));

    addMapVisualizationBtn = new JButton("Add");
    addMapVisualizationBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ArrayList<Object> visRow = new ArrayList<Object>(7);
            //TODO: Add combo box for all variable entries
            //don't add if locations is null or empty 
            //don't add if locations is not null but other conditions are false
            visRow.add(mapTypeCB.getSelectedItem());
            visRow.add(locationsCB.getSelectedItem());
            visRow.add(destinationsCB.getSelectedItem());
            visRow.add(nodeConditionCB.getSelectedItem());
            visRow.add(edgeConditionCB.getSelectedItem());
            visRow.add(showAllNodes.isSelected());
            visRow.add(iterationCountTF.getText());
            visRow.add("");//for Delete Button
            visRow.add("");//for Show Button
            visRow.add("");//for Show in browsersButton
            model.addRow(visRow);

        }
    });

    JPanel runConfig = new JPanel();
    runConfig.setLayout(new GridLayout(3, 2));

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.CENTER;
    JPanel configLabels = new JPanel(new FlowLayout());
    configLabels.add(mapTypeLabel);
    configLabels.add(sourceLabel);
    configLabels.add(destLabel);
    configLabels.add(nodeCondLabel);
    configLabels.add(edgeCondLabel);
    configLabels.add(showAllLabel);
    configLabels.add(iterationNumLabel);

    JPanel configCount = new JPanel(new FlowLayout());
    JPanel configButtons = new JPanel(new FlowLayout());
    configCount.add(mapTypeCB);
    configCount.add(locationsCB);
    configCount.add(destinationsCB);
    configCount.add(nodeConditionCB);
    configCount.add(edgeConditionCB);
    configCount.add(showAllNodes);
    configCount.add(iterationCountTF);

    configButtons.add(addMapVisualizationBtn);

    runConfig.add(configLabels);
    runConfig.add(configCount);
    runConfig.add(configButtons);
    add(runConfig, BorderLayout.SOUTH);

    setVisible(true);
}

From source file:savant.ucscexplorer.UCSCExplorerPlugin.java

private void buildUI() {
    topLevelPanel.removeAll();//from   w  w  w  .j av  a2 s  .  com
    topLevelPanel.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = new Insets(5, 5, 5, 5);

    try {
        UCSCDataSourcePlugin ucsc = getUCSCPlugin();
        ucsc.getConnection();
        JLabel cladeLabel = new JLabel("Clade:");
        gbc.anchor = GridBagConstraints.EAST;
        topLevelPanel.add(cladeLabel, gbc);

        cladeCombo = new JComboBox();
        cladeCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                UCSCDataSourcePlugin ucsc = getUCSCPlugin();
                String clade = (String) cladeCombo.getSelectedItem();
                genomeCombo.setModel(new DefaultComboBoxModel(ucsc.getCladeGenomes(clade)));
                genomeCombo.setSelectedItem(ucsc.getCurrentGenome(clade));
            }
        });

        gbc.anchor = GridBagConstraints.WEST;
        topLevelPanel.add(cladeCombo, gbc);

        JLabel genomeLabel = new JLabel("Genome:");
        gbc.anchor = GridBagConstraints.EAST;
        topLevelPanel.add(genomeLabel, gbc);

        genomeCombo = new JComboBox();
        genomeCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                buildProgressUI();
                new GroupsFetcher(getUCSCPlugin(), (GenomeDef) genomeCombo.getSelectedItem()) {
                    @Override
                    public void done(List<GroupDef> groups) {
                        if (groups != null) {
                            GridBagConstraints gbc = new GridBagConstraints();
                            gbc.gridwidth = GridBagConstraints.REMAINDER;
                            gbc.fill = GridBagConstraints.BOTH;
                            gbc.weightx = 1.0;
                            for (GroupDef g : groups) {
                                groupsPanel.add(new GroupPanel(g), gbc);
                            }

                            // Add a filler panel to force everything to the top.
                            gbc.weighty = 1.0;
                            groupsPanel.add(new JPanel(), gbc);
                            loadButton.setEnabled(true);
                            topLevelPanel.validate();
                        }
                    }

                    @Override
                    public void showProgress(double value) {
                        updateProgress(progressMessage, value);
                    }
                }.execute();
            }
        });
        gbc.anchor = GridBagConstraints.WEST;
        topLevelPanel.add(genomeCombo, gbc);

        loadButton = new JButton("Load Selected Tracks");
        loadButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    loadSelectedTracks();
                } catch (Throwable x) {
                    DialogUtils.displayException(getTitle(), "Unable to load selected tracks.", x);
                }
            }
        });
        gbc.anchor = GridBagConstraints.EAST;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        topLevelPanel.add(loadButton, gbc);

        groupsPanel = new GroupsPanel();
        groupsPanel.setLayout(new GridBagLayout());

        JScrollPane groupsScroller = new JScrollPane(groupsPanel,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        topLevelPanel.add(groupsScroller, gbc);

        buildProgressUI();

        GenomeUtils.addGenomeChangedListener(new Listener<GenomeChangedEvent>() {
            @Override
            public void handleEvent(GenomeChangedEvent event) {
                UCSCDataSourcePlugin ucsc = getUCSCPlugin();
                ucsc.selectGenomeDB(null);
                GenomeAdapter newGenome = event.getNewGenome();
                GenomeDef g = new GenomeDef(newGenome.getName(), null);
                String newClade = ucsc.findCladeForGenome(g);

                // newClade could be null if the user has opened a genome which has no UCSC equivalent.
                if (newClade != null) {
                    cladeCombo.setSelectedItem(newClade);
                }
            }
        });

        ucsc.selectGenomeDB(null);
        new CladesFetcher(getUCSCPlugin()) {
            @Override
            public void done(String selectedClade) {
                cladeCombo.setModel(new DefaultComboBoxModel(UCSCDataSourcePlugin.STANDARD_CLADES));
                if (selectedClade != null) {
                    cladeCombo.setSelectedItem(selectedClade);
                } else {
                    cladeCombo.setSelectedIndex(0);
                }
            }

            @Override
            public void showProgress(double value) {
                updateProgress(progressMessage, value);
            }
        }.execute();
    } catch (Exception x) {
        LOG.error("Unable to connect to UCSC database.", x);
        topLevelPanel.removeAll();
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 0.0;
        gbc.weighty = 0.0;
        topLevelPanel.add(new JLabel("Unable to connect to UCSC database."), gbc);
        JLabel error = new JLabel(MiscUtils.getMessage(x));
        Font f = topLevelPanel.getFont();
        f = f.deriveFont(Font.ITALIC, f.getSize() - 2.0f);
        error.setFont(f);
        topLevelPanel.add(error, gbc);
    }
}

From source file:com.sshtools.common.ui.SshToolsApplicationApplet.java

/**
 *
 *
 * @param t/*from  www . ja v a 2 s .  co  m*/
 */
protected void seriousAppletError(Throwable t) {
    StringBuffer buf = new StringBuffer();
    buf.append("<html><p>A serious error has occured ...</p><br>");
    buf.append("<p><font size=\"-1\" color=\"#ff0000\"><b>");

    StringWriter writer = new StringWriter();
    t.printStackTrace(new PrintWriter(writer, true));

    StringTokenizer tk = new StringTokenizer(writer.toString(), "\n");

    while (tk.hasMoreTokens()) {
        String msg = tk.nextToken();
        buf.append(msg);

        if (tk.hasMoreTokens()) {
            buf.append("<br>");
        }
    }

    buf.append("</b></font></p><html>");

    SshToolsApplicationAppletPanel p = new SshToolsApplicationAppletPanel();
    p.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(0, 0, 8, 0);
    gbc.fill = GridBagConstraints.NONE;
    UIUtil.jGridBagAdd(p, new JLabel(buf.toString()), gbc, GridBagConstraints.REMAINDER);
    setAppletComponent(p);
}