Example usage for javax.swing JComboBox JComboBox

List of usage examples for javax.swing JComboBox JComboBox

Introduction

In this page you can find the example usage for javax.swing JComboBox JComboBox.

Prototype

public JComboBox() 

Source Link

Document

Creates a JComboBox with a default data model.

Usage

From source file:dbmods.InsertTemplateName.java

private void addServer() {
    //START >>  jServerList
    ComboBoxModel<String> jServerListModel = new DefaultComboBoxModel<String>(SERVER);
    jServerList = new JComboBox<String>();
    getContentPane().add(jServerList);/*from ww  w.  j  av  a2  s  .c o m*/
    jServerList.setModel(jServerListModel);
    jServerList.setBounds(5, 5, 78, 23);
    //END <<  jServerList
}

From source file:Cal.java

/** Build the GUI. Assumes that setYYMMDD has been called. */
private void buildGUI() {
    getAccessibleContext().setAccessibleDescription("Calendar not accessible yet. Sorry!");
    setBorder(BorderFactory.createEtchedBorder());

    setLayout(new BorderLayout());

    JPanel tp = new JPanel();
    tp.add(monthChoice = new JComboBox());
    for (int i = 0; i < months.length; i++)
        monthChoice.addItem(months[i]);//from   w  w  w  . ja va2  s.  c  o m
    monthChoice.setSelectedItem(months[mm]);
    monthChoice.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int i = monthChoice.getSelectedIndex();
            if (i >= 0) {
                mm = i;
                // System.out.println("Month=" + mm);
                recompute();
            }
        }
    });
    monthChoice.getAccessibleContext().setAccessibleName("Months");
    monthChoice.getAccessibleContext().setAccessibleDescription("Choose a month of the year");

    tp.add(yearChoice = new JComboBox());
    yearChoice.setEditable(true);
    for (int i = yy - 5; i < yy + 5; i++)
        yearChoice.addItem(Integer.toString(i));
    yearChoice.setSelectedItem(Integer.toString(yy));
    yearChoice.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int i = yearChoice.getSelectedIndex();
            if (i >= 0) {
                yy = Integer.parseInt(yearChoice.getSelectedItem().toString());
                // System.out.println("Year=" + yy);
                recompute();
            }
        }
    });
    add(BorderLayout.CENTER, tp);

    JPanel bp = new JPanel();
    bp.setLayout(new GridLayout(7, 7));
    labs = new JButton[6][7]; // first row is days

    bp.add(b0 = new JButton("S"));
    bp.add(new JButton("M"));
    bp.add(new JButton("T"));
    bp.add(new JButton("W"));
    bp.add(new JButton("R"));
    bp.add(new JButton("F"));
    bp.add(new JButton("S"));

    ActionListener dateSetter = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String num = e.getActionCommand();
            if (!num.equals("")) {
                // set the current day highlighted
                setDayActive(Integer.parseInt(num));
                // When this becomes a Bean, you can
                // fire some kind of DateChanged event here.
                // Also, build a similar daySetter for day-of-week btns.
            }
        }
    };

    // Construct all the buttons, and add them.
    for (int i = 0; i < 6; i++)
        for (int j = 0; j < 7; j++) {
            bp.add(labs[i][j] = new JButton(""));
            labs[i][j].addActionListener(dateSetter);
        }

    add(BorderLayout.SOUTH, bp);
}

From source file:jgnash.ui.report.compiled.PayeePieChart.java

private JPanel createPanel() {

    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));

    JButton addFilterButton = new JButton(rb.getString("Button.AddFilter"));
    final JButton saveButton = new JButton(rb.getString("Button.SaveFilters"));
    JButton deleteFilterButton = new JButton(rb.getString("Button.DeleteFilter"));
    JButton clearPrefButton = new JButton(rb.getString("Button.MasterDelete"));

    filterCombo = new JComboBox<>();

    startField = new DatePanel();
    endField = new DatePanel();

    txtAddFilter = new TextField();

    filterList = new ArrayList<>();
    filtersChanged = false;/*from  ww  w. j  ava 2s.  co m*/
    useFilters = new JCheckBox(rb.getString("Label.UseFilters"));
    useFilters.setSelected(true);

    showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));

    combo = AccountListComboBox.getFullInstance();

    final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now().minusYears(1));

    long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));

    startField.setDate(DateUtils.asLocalDate(start));

    currentAccount = combo.getSelectedAccount();
    PieDataset[] data = createPieDataSet(currentAccount);
    JFreeChart chartCredit = createPieChart(currentAccount, data, 0);
    chartPanelCredit = new ChartPanel(chartCredit, true, true, true, false, true);
    //                         (chart, properties, save, print, zoom, tooltips)
    JFreeChart chartDebit = createPieChart(currentAccount, data, 1);
    chartPanelDebit = new ChartPanel(chartDebit, true, true, true, false, true);

    FormLayout layout = new FormLayout("p, $lcgap, 70dlu, 8dlu, p, $lcgap, 70dlu, $ugap, p, $lcgap:g, left:p",
            "d, $rgap, d, $ugap, f:p:g, $rgap, d");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    layout.setRowGroups(new int[][] { { 1, 3 } });

    // row 1
    builder.append(combo, 9);
    builder.append(useFilters);
    builder.nextLine();
    builder.nextLine();

    // row 3
    builder.append(rb.getString("Label.StartDate"), startField);
    builder.append(rb.getString("Label.EndDate"), endField);
    builder.append(refreshButton);
    builder.append(showPercentCheck);
    builder.nextLine();
    builder.nextLine();

    // row 5
    FormLayout subLayout = new FormLayout("180dlu:g, 1dlu, 180dlu:g", "f:180dlu:g");
    DefaultFormBuilder subBuilder = new DefaultFormBuilder(subLayout);
    subBuilder.append(chartPanelCredit);
    subBuilder.append(chartPanelDebit);

    builder.append(subBuilder.getPanel(), 11);
    builder.nextLine();
    builder.nextLine();

    // row 7
    builder.append(txtAddFilter, 3);
    builder.append(addFilterButton, 3);
    builder.append(saveButton);
    builder.nextLine();

    // row
    builder.append(filterCombo, 3);
    builder.append(deleteFilterButton, 3);
    builder.append(clearPrefButton);
    builder.nextLine();

    JPanel panel = builder.getPanel();

    combo.addActionListener(e -> {
        Account newAccount = combo.getSelectedAccount();

        if (filtersChanged) {
            int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.SaveFilters"), "Warning",
                    JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.YES_OPTION) {
                saveButton.doClick();
            }
        }
        filtersChanged = false;

        String[] list = POUND_DELIMITER_PATTERN.split(pref.get(FILTER_TAG + newAccount.hashCode(), ""));
        filterList.clear();
        for (String filter : list) {
            if (!filter.isEmpty()) {
                //System.out.println("Adding filter: #" + filter + "#");
                filterList.add(filter);
            }
        }
        refreshFilters();

        setCurrentAccount(newAccount);
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });

    refreshButton.addActionListener(e -> {
        setCurrentAccount(currentAccount);
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });

    clearPrefButton.addActionListener(e -> {
        int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.MasterDelete"), "Warning",
                JOptionPane.YES_NO_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            try {
                pref.clear();
            } catch (Exception ex) {
                System.out.println("Exception clearing preferences" + ex);
            }
        }
    });

    saveButton.addActionListener(e -> {
        final StringBuilder sb = new StringBuilder();

        for (String filter : filterList) {
            sb.append(filter);
            sb.append('#');
        }
        //System.out.println("Save = " + FILTER_TAG + currentAccount.hashCode() + " = " + sb.toString());
        pref.put(FILTER_TAG + currentAccount.hashCode(), sb.toString());
        filtersChanged = false;
    });

    addFilterButton.addActionListener(e -> {
        String newFilter = txtAddFilter.getText();
        filterList.remove(newFilter);
        if (!newFilter.isEmpty()) {
            filterList.add(newFilter);
            filtersChanged = true;
            txtAddFilter.setText("");
        }
        refreshFilters();
    });

    deleteFilterButton.addActionListener(e -> {
        if (!filterList.isEmpty()) {
            String filter = (String) filterCombo.getSelectedItem();
            filterList.remove(filter);
            filtersChanged = true;
        }
        refreshFilters();
    });

    useFilters.addActionListener(e -> setCurrentAccount(currentAccount));

    showPercentCheck.addActionListener(e -> {
        ((PiePlot) chartPanelCredit.getChart().getPlot())
                .setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
        ((PiePlot) chartPanelDebit.getChart().getPlot())
                .setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
    });

    return panel;
}

From source file:com.emr.schemas.TableRelationsForm.java

/**
 * Constructor/*from   w ww . j  a  v  a 2  s  .co  m*/
 * @param tables {@link List} List of source tables
 */
public TableRelationsForm(List tables, SchemerMapper parent) {
    fileManager = null;
    dbManager = null;
    emrConn = null;
    this.parent = parent;
    this.tables = tables; //source tables

    //Create KenyaEMR DB connection
    fileManager = new FileManager();
    String[] settings = fileManager.getConnectionSettings("emr_database.properties", "emr");
    if (settings == null) {
        //Connection settings not found
        JOptionPane.showMessageDialog(null,
                "Database Settings not found. Please set the connection settings for the database first.",
                "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE);
        //Open KenyaEMRConnectionForm form
    } else {
        if (settings.length < 1) {
            JOptionPane.showMessageDialog(null,
                    "Database Settings not found. Please set the connection settings for the database first.",
                    "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE);
            //Open KenyaEMRConnectionForm form
        } else {
            //Connection settings are ok
            //We establish a connection
            dbManager = new DatabaseManager(settings[0], settings[1], settings[3], settings[4], settings[5]);
            emrConn = dbManager.getConnection();
            if (emrConn == null) {
                JOptionPane.showMessageDialog(null, "Test Connection Failed", "Connection Test",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    //get all columns and add them to the columns list
    for (Object table : tables) {
        String tablename = (String) table;
        populateTableColumnsToList(tablename);
    }

    model = new DefaultTableModel(
            new Object[] { "Primary Table", "Column", "Reference Table", "Foreign Column" }, 10);

    initComponents();
    this.setClosable(true);
    foreignTables = tables;
    combo1 = new JComboBox();//Combobox for the primary tables
    combo2 = new JComboBox();
    combo3 = new JComboBox();
    combo4 = new JComboBox();
    combo1.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) event.getItem();
                //populate primary table columns
                primaryColumns = getTableColumns(selectedTable);
                DefaultComboBoxModel combo2_model = new DefaultComboBoxModel(
                        primaryColumns.toArray(new String[primaryColumns.size()]));
                JComboBox comboBox = new JComboBox();
                comboBox.setModel(combo2_model);
                relationsTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox));

            }
        }
    });

    combo3.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) event.getItem();
                //populate foreign table columns
                foreignColumns = getTableColumns(selectedTable);
                DefaultComboBoxModel combo3_model = new DefaultComboBoxModel(
                        foreignColumns.toArray(new String[foreignColumns.size()]));
                JComboBox comboBox = new JComboBox();
                comboBox.setModel(combo3_model);
                relationsTable.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(comboBox));
            }
        }
    });
    ComboBoxTableCellEditor primaryTableEditor = new ComboBoxTableCellEditor(tables, combo1);
    ComboBoxTableCellEditor primaryTableColumns = new ComboBoxTableCellEditor(primaryColumns, combo2);

    ComboBoxTableCellEditor foreignTableEditor = new ComboBoxTableCellEditor(foreignTables, combo3);//TODO: remove selected primary table from list

    ComboBoxTableCellEditor foreignTableColumns = new ComboBoxTableCellEditor(foreignColumns, combo4);
    relationsTable.getColumnModel().getColumn(0).setCellEditor(primaryTableEditor);
    relationsTable.getColumnModel().getColumn(1).setCellEditor(primaryTableColumns);
    relationsTable.getColumnModel().getColumn(2).setCellEditor(foreignTableEditor);
    relationsTable.getColumnModel().getColumn(3).setCellEditor(foreignTableColumns);

    columnsList.setCellRenderer(new CheckboxListCellRenderer());
    SourceTablesListener listSelectionListener = new SourceTablesListener(new JTextArea(), selected_columns);
    columnsList.addListSelectionListener(listSelectionListener);
    columnsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    columnsList.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            if (isSelectedIndex(index0))
                super.removeSelectionInterval(index0, index1);
            else
                super.addSelectionInterval(index0, index1);
        }
    });
}

From source file:EHRAppointment.ChartPanelDraw.java

private JComboBox createTrace() { //Create mouse trace
    final JComboBox trace = new JComboBox();
    final String[] traceCmds = { "Enable Trace", "Disable Trace" };
    trace.setModel(new DefaultComboBoxModel(traceCmds));
    trace.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (traceCmds[0].equals(trace.getSelectedItem())) {
                chartPanel.setHorizontalAxisTrace(true);
                chartPanel.setVerticalAxisTrace(true);
                chartPanel.repaint();/*from w  ww .j a va 2s .c  om*/
            } else {
                chartPanel.setHorizontalAxisTrace(false);
                chartPanel.setVerticalAxisTrace(false);
                chartPanel.repaint();
            }
        }
    });
    return trace;
}

From source file:gtu._work.ui.LoadJspCheckTagUI.java

private void initGUI() {
    try {//  w  w  w.j av a2  s. c o  m
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setTitle("\u8b80\u53d6Jsp\u8cc7\u8a0a");
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(475, 328));
                    {
                        jTree1 = new JTree();
                        jScrollPane1.setViewportView(jTree1);
                        jTree1.setModel(null);
                        jTree1.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                jTree1MouseClicked(evt);
                            }
                        });
                        jTree1.addTreeSelectionListener(new TreeSelectionListener() {
                            public void valueChanged(TreeSelectionEvent evt) {
                                jTree1ValueChanged(evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                jTabbedPane1.addTab("jPanel2", null, jPanel2, null);
                {
                    subFileNameText = new JTextField();
                    jPanel2.add(subFileNameText);
                    subFileNameText.setPreferredSize(new java.awt.Dimension(95, 24));
                    subFileNameText.setText("xhtml");
                }
                {
                    ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
                            new String[] { "??", "?" });
                    modifyFileBox = new JComboBox();
                    jPanel2.add(modifyFileBox);
                    modifyFileBox.setModel(jComboBox1Model);
                }
                {
                    exportReportToogleBtn = new JToggleButton();
                    jPanel2.add(exportReportToogleBtn);
                    exportReportToogleBtn.setText("\u662f\u5426\u532f\u51fa\u5831\u8868");
                    exportReportToogleBtn.setPreferredSize(new java.awt.Dimension(120, 24));
                    exportReportToogleBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            JCommonUtil.setJToggleButtonText(exportReportToogleBtn,
                                    new String[] { "", "?" });
                        }
                    });
                }
                {
                    projectSrcPathBtn = new JButton();
                    jPanel2.add(projectSrcPathBtn);
                    projectSrcPathBtn.setText("\u8a2d\u5b9a\u5c08\u6848\u76ee\u8def\u4e26\u6383\u63cf");
                    projectSrcPathBtn.setPreferredSize(new java.awt.Dimension(233, 95));
                    projectSrcPathBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                        }
                    });
                }
            }
        }
        this.setSize(496, 395);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.microsoft.alm.plugin.idea.git.ui.branch.CreateBranchForm.java

/**
 * Method generated by IntelliJ IDEA GUI Designer
 * >>> IMPORTANT!! <<<
 * DO NOT edit this method OR call it in your code!
 *
 * @noinspection ALL/*from   w w  w  .j  a  v a2s . c  o m*/
 */
private void $$$setupUI$$$() {
    contentPanel = new JPanel();
    contentPanel.setLayout(new GridLayoutManager(5, 1, new Insets(0, 0, 0, 0), -1, -1));
    nameLabel = new JLabel();
    this.$$$loadLabelText$$$(nameLabel, ResourceBundle.getBundle("com/microsoft/alm/plugin/idea/ui/tfplugin")
            .getString("CreateBranchDialog.NameLabel"));
    contentPanel.add(nameLabel,
            new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
                    false));
    remoteBranchComboBox = new JComboBox();
    contentPanel.add(remoteBranchComboBox,
            new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
                    false));
    nameTextField = new JTextField();
    contentPanel.add(nameTextField,
            new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
                    new Dimension(150, -1), null, 0, false));
    basedOn = new JLabel();
    this.$$$loadLabelText$$$(basedOn, ResourceBundle.getBundle("com/microsoft/alm/plugin/idea/ui/tfplugin")
            .getString("CreateBranchDialog.BasedOn"));
    contentPanel.add(basedOn,
            new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
                    false));
    checkoutBranch = new JCheckBox();
    checkoutBranch.setSelected(true);
    this.$$$loadButtonText$$$(checkoutBranch,
            ResourceBundle.getBundle("com/microsoft/alm/plugin/idea/ui/tfplugin")
                    .getString("CreateBranchDialog.CheckoutBranch"));
    contentPanel.add(checkoutBranch,
            new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
}

From source file:net.sf.jabref.gui.FileListEntryEditor.java

public FileListEntryEditor(JabRefFrame frame, FileListEntry entry, boolean showProgressBar,
        boolean showOpenButton, BibDatabaseContext databaseContext) {
    this.entry = entry;
    this.databaseContext = databaseContext;

    ActionListener okAction = e -> {
        // If OK button is disabled, ignore this event:
        if (!ok.isEnabled()) {
            return;
        }/*www  . j  a  v  a2  s.co  m*/
        // If necessary, ask the external confirm object whether we are ready to close.
        if (externalConfirm != null) {
            // Construct an updated FileListEntry:
            storeSettings(entry);
            if (!externalConfirm.confirmClose(entry)) {
                return;
            }
        }
        diag.dispose();
        storeSettings(FileListEntryEditor.this.entry);
        okPressed = true;
    };
    types = new JComboBox<>();
    types.addItemListener(itemEvent -> {
        if (!okDisabledExternally) {
            ok.setEnabled(types.getSelectedItem() != null);
        }
    });

    FormBuilder builder = FormBuilder.create().layout(new FormLayout(
            "left:pref, 4dlu, fill:150dlu, 4dlu, fill:pref, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p"));
    builder.add(Localization.lang("Link")).xy(1, 1);
    builder.add(link).xy(3, 1);
    final BrowseListener browse = new BrowseListener(frame, link);
    final JButton browseBut = new JButton(Localization.lang("Browse"));
    browseBut.addActionListener(browse);
    builder.add(browseBut).xy(5, 1);
    JButton open = new JButton(Localization.lang("Open"));
    if (showOpenButton) {
        builder.add(open).xy(7, 1);
    }
    builder.add(Localization.lang("Description")).xy(1, 3);
    builder.add(description).xyw(3, 3, 3);
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    builder.add(Localization.lang("File type")).xy(1, 5);
    builder.add(types).xyw(3, 5, 3);
    if (showProgressBar) {
        builder.appendRows("2dlu, p");
        builder.add(downloadLabel).xy(1, 7);
        builder.add(prog).xyw(3, 7, 3);
    }

    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addRelatedGap();
    bb.addButton(ok);
    JButton cancel = new JButton(Localization.lang("Cancel"));
    bb.addButton(cancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    ok.addActionListener(okAction);
    // Add OK action to the two text fields to simplify entering:
    link.addActionListener(okAction);
    description.addActionListener(okAction);

    open.addActionListener(e -> openFile());

    AbstractAction cancelAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            diag.dispose();
        }
    };
    cancel.addActionListener(cancelAction);

    // Key bindings:
    ActionMap am = builder.getPanel().getActionMap();
    InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);

    link.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent documentEvent) {
            checkExtension();
        }

        @Override
        public void removeUpdate(DocumentEvent documentEvent) {
            // Do nothing
        }

        @Override
        public void changedUpdate(DocumentEvent documentEvent) {
            checkExtension();
        }

    });

    diag = new JDialog(frame, Localization.lang("Save file"), true);
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    diag.pack();
    diag.setLocationRelativeTo(frame);
    diag.addWindowListener(new WindowAdapter() {

        @Override
        public void windowActivated(WindowEvent event) {
            if (openBrowseWhenShown && !dontOpenBrowseUntilDisposed) {
                dontOpenBrowseUntilDisposed = true;
                SwingUtilities.invokeLater(() -> browse.actionPerformed(new ActionEvent(browseBut, 0, "")));
            }
        }

        @Override
        public void windowClosed(WindowEvent event) {
            dontOpenBrowseUntilDisposed = false;
        }
    });
    setValues(entry);
}

From source file:DefaultsDisplay.java

protected JComponent createLookAndFeelControl() {
    JPanel panel = new JPanel();

    JLabel label = new JLabel("Current Look and Feel");
    lookAndFeelComboBox = new JComboBox();
    label.setLabelFor(lookAndFeelComboBox);
    panel.add(label);//from  w  w w.ja  v a 2 s.c  o m
    panel.add(lookAndFeelComboBox);

    // Look for toolkit look and feels first
    UIManager.LookAndFeelInfo lookAndFeelInfos[] = UIManager.getInstalledLookAndFeels();
    lookAndFeelsMap = new HashMap<String, String>();
    for (UIManager.LookAndFeelInfo info : lookAndFeelInfos) {
        String name = info.getName();
        // workaround for problem where Info and name property don't match on OS X
        if (name.equals("Mac OS X")) {
            name = OSXLookAndFeelName;
        }
        // workaround for bug where Nimbus classname is incorrect
        lookAndFeelsMap.put(name, name.equals("Nimbus") ? "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"
                : info.getClassName());
        lookAndFeelComboBox.addItem(name);
    }
    lookAndFeelComboBox.setSelectedItem(UIManager.getLookAndFeel().getName());
    lookAndFeelComboBox.addActionListener(new ChangeLookAndFeelAction());

    return panel;
}

From source file:eu.europa.ec.markt.dss.applet.util.ComponentFactory.java

/**
 * //  w w w . j av a 2 s.  co  m
 * @param model
 * @param actionListener
 * @return
 */
public static JComboBox combo(final ComboBoxModel model, final ActionListener actionListener) {
    final JComboBox combo = new JComboBox();
    combo.setModel(model);
    combo.addActionListener(actionListener);
    return combo;
}