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(Vector<E> items) 

Source Link

Document

Creates a JComboBox that contains the elements in the specified Vector.

Usage

From source file:ListSelectionDemo.java

public ListSelectionDemo() {
    super(new BorderLayout());

    String[] listData = { "one", "two", "three", "four", "five", "six", "seven" };
    String[] columnNames = { "French", "Spanish", "Italian" };
    list = new JList(listData);

    listSelectionModel = list.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    JScrollPane listPane = new JScrollPane(list);

    JPanel controlPane = new JPanel();
    String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);//  ww w .j  av  a2s  .co  m
    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String newMode = (String) comboBox.getSelectedItem();
            if (newMode.equals("SINGLE_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            } else {
                listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            output.append("----------" + "Mode: " + newMode + "----------" + newline);
        }
    });
    controlPane.add(new JLabel("Selection mode:"));
    controlPane.add(comboBox);

    // Build output area.
    output = new JTextArea(1, 10);
    output.setEditable(false);
    JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // Do the layout.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(splitPane, BorderLayout.CENTER);

    JPanel topHalf = new JPanel();
    topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS));
    JPanel listContainer = new JPanel(new GridLayout(1, 1));
    listContainer.setBorder(BorderFactory.createTitledBorder("List"));
    listContainer.add(listPane);

    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    // topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(100, 50));
    topHalf.setPreferredSize(new Dimension(100, 110));
    splitPane.add(topHalf);

    JPanel bottomHalf = new JPanel(new BorderLayout());
    bottomHalf.add(controlPane, BorderLayout.PAGE_START);
    bottomHalf.add(outputPane, BorderLayout.CENTER);
    // XXX: next line needed if bottomHalf is a scroll pane:
    // bottomHalf.setMinimumSize(new Dimension(400, 50));
    bottomHalf.setPreferredSize(new Dimension(450, 135));
    splitPane.add(bottomHalf);
}

From source file:com.diversityarrays.kdxplore.curate.fieldview.OverviewDialog.java

@SuppressWarnings("unchecked")
public OverviewDialog(Window window, String title,

        @SuppressWarnings("rawtypes") ComboBoxModel comboBoxModel, CurationData curationData,
        Transformer<TraitInstance, String> tiNameProvider, OverviewInfoProvider overviewInfoProvider,
        FieldViewSelectionModel fvsm, FieldLayoutTableModel fltm, CurationTableModel ctm) {
    super(window, title, ModalityType.MODELESS);

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    setAlwaysOnTop(true);/*ww w . j  a  v  a2 s .  c o  m*/

    this.fieldViewSelectionModel = fvsm;

    @SuppressWarnings({ "rawtypes" })
    JComboBox activeTiCombo = new JComboBox(comboBoxModel);
    TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer(
            curationData.getTraitColorProvider(), tiNameProvider);
    activeTiCombo.setRenderer(tiCellRenderer);

    JLabel infoLabel = new JLabel(" ");
    infoLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));

    final JFrame[] helpDialog = new JFrame[1];
    Action helpAction = new AbstractAction("?") {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (helpDialog[0] != null) {
                GuiUtil.restoreFrame(helpDialog[0]);
            } else {
                JFrame f = new JFrame("Overview Help");
                helpDialog[0] = f;
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                f.setAlwaysOnTop(true);
                f.setLocationRelativeTo(overview);
                String html = Overview.getOverviewHelpHtml();
                JLabel label = new JLabel(html);
                label.setBorder(new EmptyBorder(0, 10, 0, 10));
                f.setContentPane(label);
                f.pack();
                f.setVisible(true);
            }
        }
    };

    //        Window window = GuiUtil.getOwnerWindow(FieldLayoutViewPanel.this);
    if (window != null) {
        if (window instanceof JFrame) {
            System.out.println("Found window: " + ((JFrame) window).getTitle());
        }
        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                window.removeWindowListener(this);
                if (helpDialog[0] != null) {
                    helpDialog[0].dispose();
                }
            }
        });
    }

    KDClientUtils.initAction(ImageId.HELP_24, helpAction, "Help for Overview");
    Box top = Box.createHorizontalBox();
    top.add(activeTiCombo);
    top.add(new JButton(helpAction));

    overview = new Overview(overviewInfoProvider, fltm, curationData, ctm, infoLabel);
    overview.setActiveTraitInstance(fvsm.getActiveTraitInstance(true));
    Container cp = getContentPane();

    cp.add(top, BorderLayout.NORTH);
    //      cp.add(traitLabel, BorderLayout.NORTH);
    cp.add(infoLabel, BorderLayout.SOUTH);
    cp.add(overview, BorderLayout.CENTER);

    pack();
    //      setResizable(false);

    //      setLocationRelativeTo(showOverviewButton);
    // DEFAULT POSITION is "out of the way"
    setVisible(true);

    this.fieldViewSelectionModel.addListSelectionListener(listSelectionListener);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            toFront();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            fieldViewSelectionModel.removeListSelectionListener(listSelectionListener);
            removeWindowListener(this);
        }
    });
}

From source file:captureplugin.drivers.DeviceCreatorDialog.java

/**
 * Create the GUI//from   www . j a v a 2 s. c  o m
 */
private void createGUI() {
    UiUtilities.registerForClosing(this);

    DriverIf[] drivers = DriverFactory.getInstance().getDrivers();

    mDriverCombo = new JComboBox(drivers);
    mDriverCombo.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {

            if (value instanceof DriverIf) {
                value = ((DriverIf) value).getDriverName();
            }

            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });

    JPanel panel = (JPanel) getContentPane();

    panel.setLayout(new GridBagLayout());

    GridBagConstraints label = new GridBagConstraints();

    label.insets = new Insets(5, 5, 5, 5);
    label.anchor = GridBagConstraints.NORTHWEST;

    GridBagConstraints input = new GridBagConstraints();

    input.fill = GridBagConstraints.HORIZONTAL;
    input.weightx = 1.0;
    input.gridwidth = GridBagConstraints.REMAINDER;
    input.insets = new Insets(5, 5, 5, 5);

    panel.add(new JLabel(mLocalizer.msg("Name", "Name")), label);

    mName = new JTextField();
    panel.add(mName, input);

    panel.add(new JLabel(mLocalizer.msg("Driver", "Driver")), label);
    panel.add(mDriverCombo, input);

    mDesc = UiUtilities.createHtmlHelpTextArea("");
    mDesc.setEditable(false);

    panel.add(new JLabel(mLocalizer.msg("Description", "Description")), input);

    GridBagConstraints descC = new GridBagConstraints();
    descC.weightx = 1.0;
    descC.weighty = 1.0;
    descC.fill = GridBagConstraints.BOTH;
    descC.gridwidth = GridBagConstraints.REMAINDER;
    descC.insets = new Insets(5, 5, 5, 5);

    panel.add(new JScrollPane(mDesc, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), descC);

    final Font font = new JLabel().getFont();

    String desc = ((DriverIf) mDriverCombo.getSelectedItem()).getDriverDesc();
    desc = "<html><div style=\"color:#000000;font-family:" + font.getName() + "; font-size:" + font.getSize()
            + ";\">" + desc + "</div></html>";
    mDesc.setText(desc);
    mDesc.setFont(font);

    mDriverCombo.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            String description = ((DriverIf) mDriverCombo.getSelectedItem()).getDriverDesc();
            description = "<html><div style=\"color:#000000;font-family:" + font.getName() + "; font-size:"
                    + font.getSize() + ";\">" + description + "</div></html>";
            mDesc.setText(description);
            mDesc.setFont(font);
        }

    });

    final JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK));
    ok.setEnabled(false);
    final JButton cancel = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL));
    ok.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            okPressed();
        }
    });

    cancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            setVisible(false);
        }
    });

    mName.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateButtons();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateButtons();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateButtons();
        }

        private void updateButtons() {
            ok.setEnabled(!mName.getText().trim().isEmpty());
        }
    });

    ButtonBarBuilder2 builder = new ButtonBarBuilder2();
    builder.addGlue();
    builder.addButton(new JButton[] { ok, cancel });

    getRootPane().setDefaultButton(ok);

    input.insets = new Insets(5, 5, 5, 5);

    panel.add(builder.getPanel(), input);

    setSize(400, 300);

}

From source file:com.titan.storagepanel.DownloadImageDialog.java

public DownloadImageDialog(final Frame frame) {
    super(frame, true);
    setTitle("Openstack vm os image");
    setBounds(100, 100, 947, 706);/*from  www . j a  v a2 s  . com*/
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));
    {
        JPanel panel = new JPanel();
        contentPanel.add(panel, BorderLayout.NORTH);
        panel.setLayout(new MigLayout("", "[41px][107.00px][27px][95.00px][24px][95.00px][]", "[27px]"));
        {
            JLabel lblSearch = new JLabel("Search");
            panel.add(lblSearch, "cell 0 0,alignx left,aligny center");
        }
        {
            searchTextField = new JSearchTextField();
            searchTextField.setPreferredSize(new Dimension(150, 40));
            panel.add(searchTextField, "cell 1 0,growx,aligny center");
        }
        {
            JLabel lblType = new JLabel("Type");
            panel.add(lblType, "cell 2 0,alignx left,aligny center");
        }
        {
            typeComboBox = new JComboBox(
                    new String[] { "All", "Ubuntu", "Fedora", "Redhat", "CentOS", "Gentoo", "Windows" });
            panel.add(typeComboBox, "cell 3 0,growx,aligny top");
        }
        {
            JLabel lblSize = new JLabel("Size");
            panel.add(lblSize, "cell 4 0,alignx left,aligny center");
        }
        {
            sizeComboBox = new JComboBox(new String[] { "0-700MB", ">700MB" });
            panel.add(sizeComboBox, "cell 5 0,growx,aligny top");
        }
        {
            JButton btnSearch = new JButton("Search");
            btnSearch.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    d.setVisible(true);
                }
            });
            panel.add(btnSearch, "cell 6 0");
        }
    }
    {
        JScrollPane scrollPane = new JScrollPane();
        contentPanel.add(scrollPane, BorderLayout.CENTER);
        {
            table = new JTable();
            table.setModel(tableModel);
            table.addMouseListener(new JTableButtonMouseListener(table));
            table.addMouseMotionListener(new JTableButtonMouseListener(table));
            scrollPane.setViewportView(table);
        }
    }
    {
        JPanel panel = new JPanel();
        getContentPane().add(panel, BorderLayout.SOUTH);
        {
            JButton downloadButton = new JButton("Download");
            downloadButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if (table.getSelectedRowCount() == 1) {
                        JFileChooser jf = new JFileChooser();
                        int x = jf.showSaveDialog(frame);
                        if (x == JFileChooser.APPROVE_OPTION) {
                            DownloadImage p = (DownloadImage) table.getValueAt(table.getSelectedRow(), 0);
                            DownloadFileDialog d = new DownloadFileDialog(frame, "Downloading image", true,
                                    p.file, jf.getSelectedFile());
                            CommonLib.centerDialog(d);
                            d.setVisible(true);
                        }
                    }
                }
            });
            panel.add(downloadButton);
        }
    }

    d = new JProgressBarDialog(frame, true);
    d.progressBar.setIndeterminate(true);
    d.progressBar.setStringPainted(true);
    d.thread = new Thread() {
        public void run() {
            InputStream in = null;
            tableModel.columnNames.clear();
            tableModel.columnNames.add("image");
            tableModel.editables.clear();
            tableModel.editables.put(0, true);
            Vector<Object> col1 = new Vector<Object>();
            try {
                d.progressBar.setString("connecting to titan image site");
                in = new URL("http://titan-image.kingofcoders.com/titan-image.xml").openStream();
                String xml = IOUtils.toString(in);
                NodeList list = TitanCommonLib.getXPathNodeList(xml, "/images/image");
                for (int x = 0; x < list.getLength(); x++) {
                    DownloadImage downloadImage = new DownloadImage();
                    downloadImage.author = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/author/text()");
                    downloadImage.authorEmail = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/authorEmail/text()");
                    downloadImage.License = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/License/text()");
                    downloadImage.description = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/description/text()");
                    downloadImage.file = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/file/text()");
                    downloadImage.os = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/os/text()");
                    downloadImage.osType = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/osType/text()");
                    downloadImage.uploadDate = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(
                            TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/uploadDate/text()"));
                    downloadImage.size = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/size/text()");
                    downloadImage.architecture = TitanCommonLib.getXPath(xml,
                            "/images/image[" + (x + 1) + "]/architecture/text()");
                    col1.add(downloadImage);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(frame, "Unable to connect titan image site !", "Error",
                        JOptionPane.ERROR_MESSAGE);
            } finally {
                IOUtils.closeQuietly(in);
            }
            tableModel.values.clear();
            tableModel.values.add(col1);
            tableModel.fireTableStructureChanged();
            table.getColumnModel().getColumn(0).setCellRenderer(new DownloadImageTableCellRenderer());
            //            table.getColumnModel().getColumn(0).setCellEditor(new DownloadImageTableCellEditor());
            for (int x = 0; x < table.getRowCount(); x++) {
                table.setRowHeight(x, 150);
            }
        }
    };
    d.setVisible(true);
}

From source file:projects.tgas.exec.HrDiagram.java

/**
 * Main constructor./*from  w ww  . jav a 2 s  .  co  m*/
 */
public HrDiagram() {

    tgasStars = TgasUtils.loadTgasCatalogue();

    method = METHOD.NAIVE;
    fMax = 1.0;

    final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values());
    methodComboBox.setSelectedItem(method);
    methodComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            method = (METHOD) methodComboBox.getSelectedItem();
            updateChart();
        }
    });

    final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f");
    fSlider.setValue((int) Math.rint(100.0 * fMax / 2.0));
    final JLabel fLabel = new JLabel(getFLabel());
    // Create a change listener fot these
    ChangeListener cl = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();

            if (source == fSlider) {
                // Compute fractional parallax error from slider position
                double newF = (2.0 * source.getValue() / 100.0);
                fMax = newF;
                fLabel.setText(getFLabel());
            }
            updateChart();
        }
    };
    fSlider.addChangeListener(cl);
    // Add a bit of padding to space things out
    fSlider.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Present controls below the HR diagram
    JPanel controls = new JPanel(new GridLayout(2, 2));
    controls.add(new JLabel("Distance estimation method:"));
    controls.add(methodComboBox);
    controls.add(fLabel);
    controls.add(fSlider);

    // Initialise the ChartPanel
    updateChart();

    // Build the panel contents
    setLayout(new BorderLayout());
    add(hrDiagPanel, BorderLayout.CENTER);
    add(controls, BorderLayout.SOUTH);
}

From source file:FontPicker.java

public FontChooser(Frame parent) {
    super(parent, "Font Chooser", true);
    setSize(450, 450);/* w w w  . j  ava  2s. c o  m*/
    attributes = new SimpleAttributeSet();

    // Make sure that any way the user cancels the window does the right
    // thing
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            closeAndCancel();
        }
    });

    // Start the long process of setting up our interface
    Container c = getContentPane();

    JPanel fontPanel = new JPanel();
    fontName = new JComboBox(new String[] { "TimesRoman", "Helvetica", "Courier" });
    fontName.setSelectedIndex(1);
    fontName.addActionListener(this);
    fontSize = new JTextField("12", 4);
    fontSize.setHorizontalAlignment(SwingConstants.RIGHT);
    fontSize.addActionListener(this);
    fontBold = new JCheckBox("Bold");
    fontBold.setSelected(true);
    fontBold.addActionListener(this);
    fontItalic = new JCheckBox("Italic");
    fontItalic.addActionListener(this);

    fontPanel.add(fontName);
    fontPanel.add(new JLabel(" Size: "));
    fontPanel.add(fontSize);
    fontPanel.add(fontBold);
    fontPanel.add(fontItalic);

    c.add(fontPanel, BorderLayout.NORTH);

    // Set up the color chooser panel and attach a change listener so that
    // color
    // updates get reflected in our preview label.
    colorChooser = new JColorChooser(Color.black);
    colorChooser.getSelectionModel().addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            updatePreviewColor();
        }
    });
    c.add(colorChooser, BorderLayout.CENTER);

    JPanel previewPanel = new JPanel(new BorderLayout());
    previewLabel = new JLabel("Here's a sample of this font.");
    previewLabel.setForeground(colorChooser.getColor());
    previewPanel.add(previewLabel, BorderLayout.CENTER);

    // Add in the Ok and Cancel buttons for our dialog box
    JButton okButton = new JButton("Ok");
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            closeAndSave();
        }
    });
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            closeAndCancel();
        }
    });

    JPanel controlPanel = new JPanel();
    controlPanel.add(okButton);
    controlPanel.add(cancelButton);
    previewPanel.add(controlPanel, BorderLayout.SOUTH);

    // Give the preview label room to grow.
    previewPanel.setMinimumSize(new Dimension(100, 100));
    previewPanel.setPreferredSize(new Dimension(100, 100));

    c.add(previewPanel, BorderLayout.SOUTH);
}

From source file:net.sf.mzmine.modules.visualization.ida.IDABottomPanel.java

IDABottomPanel(IDAVisualizerWindow masterFrame, RawDataFile dataFile, ParameterSet parameters) {

    this.dataFile = dataFile;
    this.masterFrame = masterFrame;

    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

    setBackground(Color.white);/* w  w  w  . j  a v  a 2s .co m*/
    setBorder(new EmptyBorder(5, 5, 5, 0));

    add(Box.createHorizontalGlue());

    GUIUtils.addLabel(this, "Show: ", SwingConstants.RIGHT);

    thresholdCombo = new JComboBox<Object>(PeakThresholdMode.values());
    thresholdCombo.setSelectedItem(PeakThresholdMode.NONE);
    thresholdCombo.setBackground(Color.white);
    thresholdCombo.setFont(smallFont);
    thresholdCombo.addActionListener(this);
    add(thresholdCombo);

    JPanel peakThresholdPanel = new JPanel();
    peakThresholdPanel.setBackground(Color.white);
    peakThresholdPanel.setLayout(new BoxLayout(peakThresholdPanel, BoxLayout.X_AXIS));

    GUIUtils.addLabel(peakThresholdPanel, "Value: ", SwingConstants.RIGHT);

    peakTextField = new JTextField();
    peakTextField.setPreferredSize(new Dimension(50, 15));
    peakTextField.setFont(smallFont);
    peakTextField.addActionListener(this);
    peakThresholdPanel.add(peakTextField);
    add(peakThresholdPanel);

    GUIUtils.addLabel(this, " from peak list: ", SwingConstants.RIGHT);

    peakListSelector = new JComboBox<PeakList>();
    peakListSelector.setBackground(Color.white);
    peakListSelector.setFont(smallFont);
    peakListSelector.addActionListener(masterFrame);
    peakListSelector.setActionCommand("PEAKLIST_CHANGE");
    add(peakListSelector);

    thresholdSettings = parameters.getParameter(IDAParameters.peakThresholdSettings);

    thresholdCombo.setSelectedItem(thresholdSettings.getMode());

    add(Box.createHorizontalStrut(10));

    add(Box.createHorizontalGlue());

}

From source file:net.sf.mzmine.modules.visualization.msms.MsMsBottomPanel.java

MsMsBottomPanel(MsMsVisualizerWindow masterFrame, RawDataFile dataFile, ParameterSet parameters) {

    this.dataFile = dataFile;
    this.masterFrame = masterFrame;

    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

    setBackground(Color.white);//from w w w.  j  a va  2s  . co m
    setBorder(new EmptyBorder(5, 5, 5, 0));

    add(Box.createHorizontalGlue());

    GUIUtils.addLabel(this, "Show: ", SwingConstants.RIGHT);

    thresholdCombo = new JComboBox<Object>(PeakThresholdMode.values());
    thresholdCombo.setSelectedItem(PeakThresholdMode.NONE);
    thresholdCombo.setBackground(Color.white);
    thresholdCombo.setFont(smallFont);
    thresholdCombo.addActionListener(this);
    add(thresholdCombo);

    JPanel peakThresholdPanel = new JPanel();
    peakThresholdPanel.setBackground(Color.white);
    peakThresholdPanel.setLayout(new BoxLayout(peakThresholdPanel, BoxLayout.X_AXIS));

    GUIUtils.addLabel(peakThresholdPanel, "Value: ", SwingConstants.RIGHT);

    peakTextField = new JTextField();
    peakTextField.setPreferredSize(new Dimension(50, 15));
    peakTextField.setFont(smallFont);
    peakTextField.addActionListener(this);
    peakThresholdPanel.add(peakTextField);
    add(peakThresholdPanel);

    GUIUtils.addLabel(this, " from peak list: ", SwingConstants.RIGHT);

    peakListSelector = new JComboBox<PeakList>();
    peakListSelector.setBackground(Color.white);
    peakListSelector.setFont(smallFont);
    peakListSelector.addActionListener(masterFrame);
    peakListSelector.setActionCommand("PEAKLIST_CHANGE");
    add(peakListSelector);

    thresholdSettings = parameters.getParameter(MsMsParameters.peakThresholdSettings);

    thresholdCombo.setSelectedItem(thresholdSettings.getMode());

    add(Box.createHorizontalStrut(10));

    add(Box.createHorizontalGlue());

}

From source file:StrokeChooserPanel.java

/**
 * Creates a panel containing a combo-box that allows the user to select
 * one stroke from a list of available strokes.
 *
 * @param current  the current stroke sample.
 * @param available  an array of 'available' stroke samples.
 *//*from w  w  w.  j  a va  2  s.c  o m*/
public StrokeChooserPanel(StrokeSample current, StrokeSample[] available) {
    setLayout(new BorderLayout());
    // we've changed the behaviour here to populate the combo box
    // with Stroke objects directly - ideally we'd change the signature
    // of the constructor too...maybe later.
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (int i = 0; i < available.length; i++) {
        model.addElement(available[i].getStroke());
    }
    this.selector = new JComboBox(model);
    this.selector.setSelectedItem(current.getStroke());
    this.selector.setRenderer(new StrokeSample(null));
    add(this.selector);
    // Changes due to focus problems!! DZ
    this.selector.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent evt) {
            getSelector().transferFocus();
        }
    });
}

From source file:DesktopManagerDemo.java

public DesktopManagerDemo() {
    setTitle("Animated DesktopManager");
    m_count = m_tencount = 0;//from w w  w  . j a  v  a 2  s .co m

    JPanel innerListenerPanel = new JPanel(new GridLayout(15, 1));
    JPanel listenerPanel = new JPanel(new BorderLayout());
    m_dmEventCanvas = new DMEventCanvas();

    m_lActivates = new JLabel("activateFrame");
    m_lBegindrags = new JLabel("beginDraggingFrame");
    m_lBeginresizes = new JLabel("beginResizingFrame");
    m_lCloses = new JLabel("closeFrame");
    m_lDeactivates = new JLabel("deactivateFrame");
    m_lDeiconifies = new JLabel("deiconifyFrame");
    m_lDrags = new JLabel("dragFrame");
    m_lEnddrags = new JLabel("endDraggingFrame");
    m_lEndresizes = new JLabel("endResizingFrame");
    m_lIconifies = new JLabel("iconifyFrame");
    m_lMaximizes = new JLabel("maximizeFrame");
    m_lMinimizes = new JLabel("minimizeFrame");
    m_lOpens = new JLabel("openFrame");
    m_lResizes = new JLabel("resizeFrame");
    m_lSetbounds = new JLabel("setBoundsForFrame");

    innerListenerPanel.add(m_lActivates);
    innerListenerPanel.add(m_lBegindrags);
    innerListenerPanel.add(m_lBeginresizes);
    innerListenerPanel.add(m_lCloses);
    innerListenerPanel.add(m_lDeactivates);
    innerListenerPanel.add(m_lDeiconifies);
    innerListenerPanel.add(m_lDrags);
    innerListenerPanel.add(m_lEnddrags);
    innerListenerPanel.add(m_lEndresizes);
    innerListenerPanel.add(m_lIconifies);
    innerListenerPanel.add(m_lMaximizes);
    innerListenerPanel.add(m_lMinimizes);
    innerListenerPanel.add(m_lOpens);
    innerListenerPanel.add(m_lResizes);
    innerListenerPanel.add(m_lSetbounds);

    listenerPanel.add("Center", m_dmEventCanvas);
    listenerPanel.add("West", innerListenerPanel);
    listenerPanel.setOpaque(true);
    listenerPanel.setBackground(Color.white);

    m_myDesktopManager = new MyDesktopManager();
    m_desktop = new JDesktopPane();
    m_desktop.setDesktopManager(m_myDesktopManager);
    m_desktop.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
    m_newFrame = new JButton("New Frame");
    m_newFrame.addActionListener(this);
    m_infos = UIManager.getInstalledLookAndFeels();
    String[] LAFNames = new String[m_infos.length];
    for (int i = 0; i < m_infos.length; i++) {
        LAFNames[i] = m_infos[i].getName();
    }
    m_UIBox = new JComboBox(LAFNames);
    m_UIBox.addActionListener(this);
    JPanel topPanel = new JPanel(true);
    topPanel.setLayout(new FlowLayout());
    topPanel.setBorder(new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED),
            new CompoundBorder(new EmptyBorder(2, 2, 2, 2), new SoftBevelBorder(BevelBorder.RAISED))));
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add("North", topPanel);
    getContentPane().add("Center", m_desktop);
    getContentPane().add("South", listenerPanel);
    ((JPanel) getContentPane()).setBorder(new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED),
            new CompoundBorder(new EmptyBorder(1, 1, 1, 1), new SoftBevelBorder(BevelBorder.RAISED))));
    topPanel.add(m_newFrame);
    topPanel.add(new JLabel("Look & Feel:", SwingConstants.RIGHT));
    topPanel.add(m_UIBox);
    setSize(645, 600);
    Dimension dim = getToolkit().getScreenSize();
    setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2);
    setVisible(true);
    WindowListener l = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(l);
    m_eventTimer = new Timer(1000, this);
    m_eventTimer.setRepeats(true);
    m_eventTimer.start();
}