Example usage for javax.swing DefaultComboBoxModel addElement

List of usage examples for javax.swing DefaultComboBoxModel addElement

Introduction

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

Prototype

public void addElement(E anObject) 

Source Link

Usage

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

private void jText1OrJArea1Change(DocumentEvent doc) {
    try {//from  ww  w  . j av  a 2s.c  om
        String complie1 = regexText.getText();
        String complie2 = regexText0.getText();
        String complie = complie1;
        if (StringUtils.isBlank(complie1)) {
            complie = complie2;
        }

        String matcherStr = srcArea.getText();

        if (StringUtils.isBlank(complie)) {
            setTitle("Regex");
            return;
        }
        if (StringUtils.isBlank(matcherStr)) {
            setTitle("content");
            return;
        }

        Pattern pattern = Pattern.compile(complie);
        Matcher matcher = pattern.matcher(matcherStr);

        DefaultComboBoxModel model1 = new DefaultComboBoxModel();
        groupList.setModel(model1);
        while (matcher.find()) {
            model1.addElement("---------------------");
            for (int ii = 0; ii <= matcher.groupCount(); ii++) {
                model1.addElement(ii + " : [" + matcher.group(ii) + "]");
            }
        }

        DefaultComboBoxModel model2 = new DefaultComboBoxModel();
        scannerList.setModel(model2);
        Scanner scanner = new Scanner(matcherStr);
        scanner.useDelimiter(pattern);
        while (scanner.hasNext()) {
            model2.addElement("[" + scanner.next() + "]");
        }
        scanner.close();
        this.setTitle("?");
    } catch (Exception ex) {
        this.setTitle(ex.getMessage());
        ex.printStackTrace();
    }
}

From source file:com.floreantpos.config.ui.AddPrinterDialog.java

protected void doAddNewVirtualPrinter() {
    VirtualPrinterConfigDialog dialog = new VirtualPrinterConfigDialog();
    dialog.open();//w w  w.j a  v a2s . c o  m

    if (dialog.isCanceled()) {
        return;
    }

    VirtualPrinter virtualPrinter = dialog.getPrinter();
    DefaultComboBoxModel<VirtualPrinter> model = (DefaultComboBoxModel<VirtualPrinter>) cbVirtualPrinter
            .getModel();
    model.addElement(virtualPrinter);
    cbVirtualPrinter.setSelectedItem(virtualPrinter);
}

From source file:Main.java

private void setContents(Node node) {
    if (node == null) {
        return;/*  www.ja v a2  s  .  co m*/
    }
    ValueName.setText(node.toString());
    DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) comboBox.getModel();
    model.removeAllElements();
    if (node.getValues().length > 0) {
        panel.add(comboBox);
        for (String s : node.getValues()) {
            model.addElement(s);
        }
        comboBox.setSelectedIndex(node.getMyIndex());
    } else {
        panel.remove(comboBox);
    }
}

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.
 *///w ww  . j  a v a 2  s  .  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:hermes.browser.dialog.EditNamingConfigDialog.java

private ComboBoxModel createComboBoxModel() {
    DefaultComboBoxModel model = new DefaultComboBoxModel();

    if (newConfig != null) {
        model.addElement(newConfig.getId());
    }//from  w  w  w  .  jav  a 2 s  .co m

    for (Iterator iter = namingConfigs.iterator(); iter.hasNext();) {
        NamingConfig config = (NamingConfig) iter.next();

        namingConfigsByName.put(config.getId(), config);
        model.addElement(config.getId());

        if (selectedConfig == null) {
            selectedConfig = config.getId();
        }
    }

    return model;

}

From source file:com.anrisoftware.prefdialog.fields.historycombobox.HistoryComboBoxField.java

private MutableComboBoxModel<?> createMutableModel(ComboBoxModel<?> model) {
    if (model instanceof MutableComboBoxModel) {
        return (MutableComboBoxModel<?>) model;
    }/*from  www. j  av  a2  s  .c  o m*/
    DefaultComboBoxModel<Object> mutableModel = new DefaultComboBoxModel<Object>();
    for (int i = 0; i < model.getSize(); i++) {
        mutableModel.addElement(model.getElementAt(i));
    }
    return mutableModel;
}

From source file:com.floreantpos.config.ui.TerminalConfigurationView.java

private void initializeFontConfig() {
    GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = e.getAllFonts(); // Get the fonts
    DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) cbFonts.getModel();
    model.addElement("<select>"); //$NON-NLS-1$

    for (Font f : fonts) {
        model.addElement(f.getFontName());
    }//from  www .j ava 2  s .  c o  m

    String uiDefaultFont = TerminalConfig.getUiDefaultFont();
    if (StringUtils.isNotEmpty(uiDefaultFont)) {
        cbFonts.setSelectedItem(uiDefaultFont);
    }
}

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

private void initGUI() {
    try {/*from  w  ww. j av  a2s  . co  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.WeaponEditorPanel.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 to choose an Weapon or you can create a new "
                    + "Weapon entity below. Once selected a weapon, its' details will be available below</div></html>");
    noteLbl.setAlignmentX(0);//from w ww .  jav  a 2 s.  com
    add(noteLbl);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (Item item : GameBean.weaponDetails) {
        if (item instanceof Weapon) {
            model.addElement(((Weapon) item).getName());
        }
    }
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setAlignmentX(0);
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(Box.createVerticalStrut(10));
    add(comboBox);
    add(Box.createVerticalStrut(10));
    JPanel panel1 = new JPanel();
    panel1.setAlignmentX(0);
    panel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel1.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    JLabel weaponDtsLbl = new JLabel("Weapon Details : ");
    weaponDtsLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    panel1.add(weaponDtsLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    panel1.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    panel1.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel weaponTypeLbl = new JLabel("Weapon Type : ");
    panel1.add(weaponTypeLbl, c);
    c.gridx = 1;
    JComboBox weaponType = new JComboBox(Configuration.weaponTypes);
    weaponType.setSelectedIndex(0);
    weaponType.setPreferredSize(name.getPreferredSize());
    System.out.println(name.getPreferredSize());
    panel1.add(weaponType, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel attackRangeLbl = new JLabel("Attack Range : ");
    panel1.add(attackRangeLbl, c);
    c.gridx = 1;
    JTextField attackRange = new JTextField("");
    attackRange.setColumns(20);
    panel1.add(attackRange, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    panel1.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    panel1.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    panel1.add(submit, c);
    c.gridx = 0;
    c.gridy = 6;
    c.gridwidth = 2;
    c.weighty = 0;
    c.weightx = 1;
    validationMess = new JLabel("Pls enter all the fields or pls choose a weapon from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    panel1.add(validationMess, c);
    //        c.fill = GridBagConstraints.BOTH;
    //        c.gridy = 7;
    //        c.weightx = 1;
    //        c.weighty = 1;
    //        panel1.add(new JLabel(""), c);
    panel1.setBorder(LineBorder.createGrayLineBorder());
    add(panel1);
    add(Box.createVerticalGlue());
}

From source file:user.NewJPanel2.java

private void setCheckBox(String[] items) {
    DefaultComboBoxModel model = (DefaultComboBoxModel) choiceBox2.getModel();
    model.removeAllElements();/*from ww  w. ja v a 2 s  .  c om*/

    for (String item : items) {
        model.addElement(item);
    }
    choiceBox2.setModel(model);

}