Example usage for javax.swing DefaultComboBoxModel DefaultComboBoxModel

List of usage examples for javax.swing DefaultComboBoxModel DefaultComboBoxModel

Introduction

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

Prototype

public DefaultComboBoxModel() 

Source Link

Document

Constructs an empty DefaultComboBoxModel object.

Usage

From source file:eu.dety.burp.joseph.utilities.Converter.java

/**
 * Get RSA PublicKey by PublicKey HashMap input. Create a dialog popup with a combobox to choose the correct JWK to use.
 * /*  w  ww  .ja v  a 2 s  . c o  m*/
 * @param publicKeys
 *            HashMap containing a PublicKey and related describing string
 * @throws AttackPreparationFailedException
 * @return Selected {@link PublicKey}
 */
@SuppressWarnings("unchecked")
public static PublicKey getRsaPublicKeyByJwkSelectionPanel(HashMap<String, PublicKey> publicKeys)
        throws AttackPreparationFailedException {
    // TODO: Move to other class?
    JPanel selectionPanel = new JPanel();
    selectionPanel.setLayout(new java.awt.GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.HORIZONTAL;

    constraints.gridy = 0;
    selectionPanel.add(new JLabel("Multiple JWKs found. Please choose one:"), constraints);

    JComboBox jwkSetKeySelection = new JComboBox<>();
    DefaultComboBoxModel<String> jwkSetKeySelectionModel = new DefaultComboBoxModel<>();

    for (Map.Entry<String, PublicKey> publicKey : publicKeys.entrySet()) {
        jwkSetKeySelectionModel.addElement(publicKey.getKey());
    }

    jwkSetKeySelection.setModel(jwkSetKeySelectionModel);

    constraints.gridy = 1;
    selectionPanel.add(jwkSetKeySelection, constraints);

    int resultButton = JOptionPane.showConfirmDialog(null, selectionPanel, "Select JWK",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);

    if (resultButton == JOptionPane.CANCEL_OPTION) {
        throw new AttackPreparationFailedException("No JWK from JWK Set selected!");
    }

    loggerInstance.log(Converter.class, "Key selected: " + jwkSetKeySelection.getSelectedIndex(),
            Logger.LogLevel.DEBUG);
    return publicKeys.get(jwkSetKeySelection.getSelectedItem());
}

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

private void initGUI() {
    try {/*  w ww . ja  v a  2s.c  o m*/
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                FlowLayout jPanel1Layout = new FlowLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("?", null, jPanel1, null);
                {
                    DefaultComboBoxModel countryComboBoxModel = new DefaultComboBoxModel();
                    for (CountyEnum e : CountyEnum.values()) {
                        countryComboBoxModel.addElement(e.countyLabel);
                    }
                    countryComboBox = new JComboBox();
                    jPanel1.add(countryComboBox);
                    countryComboBox.setModel(countryComboBoxModel);
                }
                {
                    ComboBoxModel passRetryComboBoxModel = new DefaultComboBoxModel(
                            new String[] { "byPass", "reTry", "status" });
                    passRetryComboBox = new JComboBox();
                    jPanel1.add(passRetryComboBox);
                    passRetryComboBox.setModel(passRetryComboBoxModel);
                }
                {
                    sendBtn = new JButton();
                    jPanel1.add(sendBtn);
                    sendBtn.setText("\u9001\u51fa");
                    sendBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            //TODO add your code for sendBtn.actionPerformed
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    readMessageId();
                                }
                            }).start();
                        }
                    });
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("messageId", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(604, 375));
                    {
                        messageIdArea = new JTextArea();
                        jScrollPane1.setViewportView(messageIdArea);
                    }
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jTabbedPane1.addTab("?", null, jPanel3, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel3.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(604, 375));
                    {
                        executeLogArea = new JTextArea();
                        jScrollPane2.setViewportView(executeLogArea);
                    }
                }
            }
        }
        pack();
        this.setSize(617, 429);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:com.game.ui.views.ItemPanel.java

public void doGui() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel noteLbl = new JLabel(
            "<html><div style='width : 500px;'>Pls select a value from the dropdown or you can create a new "
                    + "entity below. Once selected an Item, its' details will be available below</div></html>");
    noteLbl.setAlignmentX(0);//from   ww  w .jav a  2s. com
    add(noteLbl);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    if (ringPanel) {
        for (Item item : GameBean.ringDetails) {
            model.addElement(((Ring) item).getName());
        }
    } else if (armourPanel) {
        for (Item item : GameBean.armourDetails) {
            model.addElement(((Armour) item).getName());
        }
    } else if (potionPanel) {
        for (Item item : GameBean.potionDetails) {
            model.addElement(((Potion) item).getName());
        }
    } else if (treasurePanel) {
        for (Item item : GameBean.treasureDetails) {
            model.addElement(((Treasure) item).getName());
        }
    }
    doCommonStuffForDropDown(model);
    doCommonStuffForContent();
}

From source file:sample.fa.ScriptRunnerApplication.java

void createGUI() {
    Box buttonBox = Box.createHorizontalBox();

    JButton loadButton = new JButton("Load");
    loadButton.addActionListener(this::loadScript);
    buttonBox.add(loadButton);//from w  w  w. j  a v  a  2s  .c o  m

    JButton saveButton = new JButton("Save");
    saveButton.addActionListener(this::saveScript);
    buttonBox.add(saveButton);

    JButton executeButton = new JButton("Execute");
    executeButton.addActionListener(this::executeScript);
    buttonBox.add(executeButton);

    languagesModel = new DefaultComboBoxModel();

    ScriptEngineManager sem = new ScriptEngineManager();
    for (ScriptEngineFactory sef : sem.getEngineFactories()) {
        languagesModel.addElement(sef.getScriptEngine());
    }

    JComboBox<ScriptEngine> languagesCombo = new JComboBox<>(languagesModel);
    JLabel languageLabel = new JLabel();
    languagesCombo.setRenderer((JList<? extends ScriptEngine> list, ScriptEngine se, int index,
            boolean isSelected, boolean cellHasFocus) -> {
        ScriptEngineFactory sef = se.getFactory();
        languageLabel.setText(sef.getEngineName() + " - " + sef.getLanguageName() + " (*."
                + String.join(", *.", sef.getExtensions()) + ")");
        return languageLabel;
    });
    buttonBox.add(Box.createHorizontalGlue());
    buttonBox.add(languagesCombo);

    scriptContents = new JTextArea();
    scriptContents.setRows(8);
    scriptContents.setColumns(40);

    scriptResults = new JTextArea();
    scriptResults.setEditable(false);
    scriptResults.setRows(8);
    scriptResults.setColumns(40);

    JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scriptContents, scriptResults);

    JFrame frame = new JFrame("Script Runner");
    frame.add(buttonBox, BorderLayout.NORTH);
    frame.add(jsp, BorderLayout.CENTER);

    frame.pack();
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    frame.setVisible(true);
}

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 va2s .c  om*/
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:com.mirth.connect.connectors.tcp.TcpListener.java

public TcpListener() {
    this.parent = PlatformUI.MIRTH_FRAME;
    initComponents();//from ww  w.j av a  2s  . com
    initToolTips();
    initLayout();

    reconnectIntervalField.setDocument(new MirthFieldConstraints(0, false, false, true));
    receiveTimeoutField.setDocument(new MirthFieldConstraints(0, false, false, true));
    bufferSizeField.setDocument(new MirthFieldConstraints(0, false, false, true));
    maxConnectionsField.setDocument(new MirthFieldConstraints(0, false, false, true));

    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();
    model.addElement("Basic TCP");
    selectedMode = "Basic TCP";

    for (String pluginPointName : LoadedExtensions.getInstance().getTransmissionModePlugins().keySet()) {
        model.addElement(pluginPointName);
        if (pluginPointName.equals("MLLP")) {
            defaultProvider = LoadedExtensions.getInstance().getTransmissionModePlugins().get(pluginPointName)
                    .createProvider();
        }
    }

    transmissionModeComboBox.setModel(model);

    parent.setupCharsetEncodingForConnector(charsetEncodingComboBox);
}

From source file:de.dal33t.powerfolder.ui.information.stats.StatsInformationCard.java

/**
 * Initialize components/*w w w  .  ja  v  a2  s  .c  o  m*/
 */
private void initialize() {
    usedDataTypeModel = new DefaultComboBoxModel();
    usedDataTypeModel.addElement(Translation.getTranslation("stats_information_card.wan_upload"));
    usedDataTypeModel.addElement(Translation.getTranslation("stats_information_card.wan_download"));
    usedDataTypeModel.addElement(Translation.getTranslation("stats_information_card.lan_upload"));
    usedDataTypeModel.addElement(Translation.getTranslation("stats_information_card.lan_download"));

    usedGraphTypeModel = new DefaultComboBoxModel();
    usedGraphTypeModel.addElement(Translation.getTranslation("stats_information_card.used_and_available"));
    usedGraphTypeModel.addElement(Translation.getTranslation("stats_information_card.used_only"));
    usedGraphTypeModel.addElement(Translation.getTranslation("stats_information_card.available_only"));
    usedGraphTypeModel.addElement(Translation.getTranslation("stats_information_card.average"));

    percentDataTypeModel = new DefaultComboBoxModel();
    percentDataTypeModel.addElement(Translation.getTranslation("stats_information_card.wan_upload"));
    percentDataTypeModel.addElement(Translation.getTranslation("stats_information_card.wan_download"));
    percentDataTypeModel.addElement(Translation.getTranslation("stats_information_card.lan_upload"));
    percentDataTypeModel.addElement(Translation.getTranslation("stats_information_card.lan_download"));

    usedBandwidthSeries = new TimeSeries(Translation.getTranslation("stats_information_card.used"), Hour.class);
    availableBandwidthSeries = new TimeSeries(Translation.getTranslation("stats_information_card.available"),
            Hour.class);
    averageBandwidthSeries = new TimeSeries(Translation.getTranslation("stats_information_card.average"),
            Hour.class);

    percentageBandwidthSeries = new TimeSeries(Translation.getTranslation("stats_information_card.percentage"),
            Hour.class);

}

From source file:geneticalgorithm.gui.view.VExperiment.java

public VExperiment() {
    setLayout(new BorderLayout());
    setSize(900, 700);//from   www.ja  va2  s  .  c o  m
    setLocationRelativeTo(this);
    setResizable(false);
    buttons = new ArrayList<JButton>();

    // CENTER

    pnlCentral = new JPanel();
    pnlCentral.setLayout(new MigLayout());
    add(pnlCentral, BorderLayout.CENTER);

    lblLocale = new JLabel();
    cmbModelSelectLocale = new DefaultComboBoxModel<String>();
    cmbSelectLocale = new JComboBox<String>(cmbModelSelectLocale);

    lblLimLow = new JLabel();
    spiLow = new JSpinner();
    spiLow.setModel(new SpinnerNumberModel(-10., -100000., 100000., .5));

    lblLimUp = new JLabel();
    spiUp = new JSpinner();
    spiUp.setModel(new SpinnerNumberModel(10., -100000., 100000., .5));

    lblChromosome = new JLabel();
    spiChromosome = new JSpinner();
    spiChromosome.setModel(new SpinnerNumberModel(10, 0, 63, 1));

    lblPopulation = new JLabel();
    spiPopulation = new JSpinner();
    spiPopulation.setModel(new SpinnerNumberModel(10, 0, 100000, 1));

    lblGenerations = new JLabel();
    spiGenerations = new JSpinner();
    spiGenerations.setModel(new SpinnerNumberModel(100, 0, 100000, 1));

    lblProbCrossover = new JLabel();
    txtProbCrossover = new JTextField("0.5");

    lblProbMutation = new JLabel();
    txtProbMutation = new JTextField("0.001");

    lblIndividual = new JLabel();
    cmbModelIndividual = new DefaultComboBoxModel<ClassWrapper>();
    cmbIndividual = new JComboBox<ClassWrapper>(cmbModelIndividual);

    lblCrossover = new JLabel();
    cmbModelCrossover = new DefaultComboBoxModel<ClassWrapper>();
    cmbCrossover = new JComboBox<ClassWrapper>(cmbModelCrossover);

    lblMutation = new JLabel();
    cmbModelMutation = new DefaultComboBoxModel<ClassWrapper>();
    cmbMutation = new JComboBox<ClassWrapper>(cmbModelMutation);

    lblSelection = new JLabel();
    cmbModelSelection = new DefaultComboBoxModel<ClassWrapper>();
    cmbSelection = new JComboBox<ClassWrapper>(cmbModelSelection);

    lblFitness = new JLabel();
    cmbModelFitness = new DefaultComboBoxModel<ClassWrapper>();
    cmbFitness = new JComboBox<ClassWrapper>(cmbModelFitness);

    lblPathOutput = new JLabel();
    txtPathOutput = new JTextField();
    btnPathOutput = new JButton("...");

    lblName = new JLabel();
    txtName = new JTextField();

    lblAverage = new JLabel("");
    lblAverage.setHorizontalTextPosition(SwingConstants.LEFT);
    lblAverageTitle = new JLabel("Average: ");

    lblOffline = new JLabel("");
    lblOffline.setHorizontalTextPosition(SwingConstants.LEFT);
    lblOfflineTitle = new JLabel("Offline: ");

    lblOnline = new JLabel("");
    lblOnline.setHorizontalTextPosition(SwingConstants.LEFT);
    lblOnlineTitle = new JLabel("Online: ");

    lblElite = new JLabel("");
    lblElite.setHorizontalTextPosition(SwingConstants.LEFT);
    lblEliteTitle = new JLabel("Elite: ");

    average = new XYSeries("Average");
    offline = new XYSeries("Offline");
    online = new XYSeries("Online");
    elite = new XYSeries("Elite");

    dataset = new XYSeriesCollection();
    dataset.addSeries(average);
    dataset.addSeries(online);
    dataset.addSeries(elite);
    dataset.addSeries(offline);

    chart = ChartFactory.createXYLineChart("title", "xLabel", "yLabel", dataset, PlotOrientation.VERTICAL, true,
            true, false);
    chartPanel = new ChartPanel(chart);

    pnlCentral.add(lblLocale, "width 120, height 25");
    pnlCentral.add(cmbSelectLocale, "width 120, height 25, wrap");

    pnlCentral.add(lblLimLow, "width 120, height 25");
    pnlCentral.add(spiLow, "width 120, height 25");
    pnlCentral.add(lblIndividual, "width 80, height 25");
    pnlCentral.add(cmbIndividual, "growx, height 25, span 2, wrap");

    pnlCentral.add(lblLimUp, "width 120, height 25");
    pnlCentral.add(spiUp, "width 120, height 25");
    pnlCentral.add(lblCrossover, "width 80, height 25");
    pnlCentral.add(cmbCrossover, "growx, height 25, span 2, wrap");

    pnlCentral.add(lblChromosome, "width 120, height 25");
    pnlCentral.add(spiChromosome, "width 120, height 25");
    pnlCentral.add(lblMutation, "width 80, height 25");
    pnlCentral.add(cmbMutation, "growx, height 25, span 2, wrap");

    pnlCentral.add(lblPopulation, "width 120, height 25");
    pnlCentral.add(spiPopulation, "width 120, height 25");
    pnlCentral.add(lblSelection, "width 80, height 25");
    pnlCentral.add(cmbSelection, "growx, height 25, span 2");
    pnlCentral.add(lblAverageTitle, "width 70, height 25");
    pnlCentral.add(lblAverage, "width 200, height 25, wrap");

    pnlCentral.add(lblGenerations, "width 120, height 25");
    pnlCentral.add(spiGenerations, "width 120, height 25");
    pnlCentral.add(lblFitness, "width 80, height 25");
    pnlCentral.add(cmbFitness, "growx, height 25, span 2");
    pnlCentral.add(lblOnlineTitle, "growx, height 25");
    pnlCentral.add(lblOnline, "growx, height 25, wrap");

    pnlCentral.add(lblProbCrossover, "width 120, height 25");
    pnlCentral.add(txtProbCrossover, "width 120, height 25");
    pnlCentral.add(lblPathOutput, "width 80, height 25");
    pnlCentral.add(txtPathOutput, "width 280, height 25");
    pnlCentral.add(btnPathOutput, "width 20, height 25");
    pnlCentral.add(lblEliteTitle, "growx, height 25");
    pnlCentral.add(lblElite, "growx, height 25, wrap");

    pnlCentral.add(lblProbMutation, "width 120, height 25");
    pnlCentral.add(txtProbMutation, "width 120, height 25");
    pnlCentral.add(lblName, "width 80, height 25");
    pnlCentral.add(txtName, "growx, height 25, span 2");
    pnlCentral.add(lblOfflineTitle, "growx, height 25");
    pnlCentral.add(lblOffline, "growx, height 25, wrap");

    pnlCentral.add(chartPanel, "growx, span 7");

    // SOUTH
    pnlSouth = new JPanel();
    add(pnlSouth, BorderLayout.SOUTH);

    btnRun = new JButton();
    btnStop = new JButton();
    btnClose = new JButton();

    pnlSouth.add(btnRun);
    pnlSouth.add(btnStop);
    pnlSouth.add(btnClose);

    // ADD BUTTONS
    buttons.add(btnClose);
    buttons.add(btnStop);
    buttons.add(btnPathOutput);
    buttons.add(btnRun);
}

From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV2.ADAP3DecompositionV2SetupDialog.java

/** Creates the interface elements */
@Override//w ww . j  a  va 2s  . com
protected void addDialogComponents() {
    super.addDialogComponents();

    comboClustersModel = new DefaultComboBoxModel<>();

    PeakList[] peakLists = MZmineCore.getDesktop().getSelectedPeakLists();

    // -----------------------------
    // Panel with preview UI elements
    // -----------------------------

    // Preview CheckBox
    chkPreview = new JCheckBox("Show preview");
    chkPreview.addActionListener(this);
    chkPreview.setHorizontalAlignment(SwingConstants.CENTER);
    chkPreview.setEnabled(peakLists != null && peakLists.length > 0);

    // Preview panel that will contain ComboBoxes
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(new JSeparator(), BorderLayout.NORTH);
    panel.add(chkPreview, BorderLayout.CENTER);
    panel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH);
    pnlUIElements = new JPanel(new BorderLayout());
    pnlUIElements.add(panel, BorderLayout.NORTH);

    // ComboBox with Clusters
    cboClusters = new JComboBox<>(comboClustersModel);
    cboClusters.setFont(COMBO_FONT);
    cboClusters.addActionListener(this);

    pnlComboBoxes = GUIUtils.makeTablePanel(1, 2, new JComponent[] { new JLabel("Clusters"), cboClusters });

    // --------------------------------------------------------------------
    // ----- Panel with plots --------------------------------------
    // --------------------------------------------------------------------

    pnlPlots = new JPanel();
    pnlPlots.setLayout(new BoxLayout(pnlPlots, BoxLayout.Y_AXIS));

    // Plot with retention-time clusters
    retTimeMZPlot = new SimpleScatterPlot("Retention time", "m/z");
    retTimeMZPlot.setMinimumSize(MIN_DIMENSIONS);

    final JPanel pnlPlotRetTimeClusters = new JPanel(new BorderLayout());
    pnlPlotRetTimeClusters.setBackground(Color.white);
    pnlPlotRetTimeClusters.add(retTimeMZPlot, BorderLayout.CENTER);
    GUIUtils.addMarginAndBorder(pnlPlotRetTimeClusters, 10);

    // Plot with chromatograms
    retTimeIntensityPlot = new EICPlot();
    retTimeIntensityPlot.setMinimumSize(MIN_DIMENSIONS);

    JPanel pnlPlotShapeClusters = new JPanel(new BorderLayout());
    pnlPlotShapeClusters.setBackground(Color.white);
    pnlPlotShapeClusters.add(retTimeIntensityPlot, BorderLayout.CENTER);
    GUIUtils.addMarginAndBorder(pnlPlotShapeClusters, 10);

    pnlPlots.add(pnlPlotRetTimeClusters);
    pnlPlots.add(pnlPlotShapeClusters);

    super.mainPanel.add(pnlUIElements, 0, super.getNumberOfParameters() + 3, 2, 1, 0, 0,
            GridBagConstraints.HORIZONTAL);
}

From source file:de.cebitec.readXplorer.differentialExpression.plot.ExpressTestGraphicsTopComponent.java

/**
 * TopComponent, which displays all graphics available for the express test.
 *//*from  w  w w . ja v  a  2  s  .co  m*/
public ExpressTestGraphicsTopComponent() {
    cbmDataSet = new DefaultComboBoxModel<>();
    initComponents();
    initAdditionalComponents();
    ChartPanel panel = CreatePlots.createInfPlot(createSamplePoints(500), "X", "Y", new ToolTip());
    plotPanel.add(panel);
    plotPanel.updateUI();

}