Example usage for javax.swing JComboBox addItem

List of usage examples for javax.swing JComboBox addItem

Introduction

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

Prototype

public void addItem(E item) 

Source Link

Document

Adds an item to the item list.

Usage

From source file:LabelForComboBox.java

public LabelForComboBox() {
    JLabel lbl = new JLabel("Color:");
    lbl.setDisplayedMnemonic('c');
    add(lbl);/*from   ww w  .  j av a  2s  . c o m*/
    add(Box.createHorizontalStrut(20));
    JComboBox cbColor = new JComboBox();
    cbColor.addItem("red");
    cbColor.addItem("blue");
    lbl.setLabelFor(cbColor);
    add(cbColor);
}

From source file:Main.java

public Main() {
    JComboBox comboBox = new JComboBox();
    comboBox.addItem(new Double(1));
    comboBox.addItem(new Double(2.25));
    comboBox.addItem(new Double(3.5));
    comboBox.setRenderer(new TwoDecimalRenderer(comboBox.getRenderer()));
    comboBox.setEditable(true);/* ww w .j  a  va 2s  .co  m*/

    JFrame frame = new JFrame();
    frame.add(comboBox, BorderLayout.NORTH);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

public FlavorsPanel() {

    JComboBox jcb = new JComboBox();
    jcb.addItem("Vanilla");
    jcb.addItem("Chocolate");
    jcb.addItem("Strawberry");
    add(jcb);//from ww w. j  a va 2s.c  o  m
}

From source file:Main.java

public Main() {
    JComboBox comboBox = new JComboBox();
    comboBox.addItem(new Item(1, "-"));
    comboBox.addItem(new Item(2, "X"));
    comboBox.addItem(new Item(3, "Y"));
    comboBox.setMaximumRowCount(3);//from w  ww  . j a va2 s.c  o m
    comboBox.setPrototypeDisplayValue(" None of the above ");
    comboBox.addActionListener(e -> {
        JComboBox c = (JComboBox) e.getSource();
        Item item = (Item) c.getSelectedItem();
        System.out.println(item.getId() + " : " + item.getDescription());
    });
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(comboBox);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public Main() {
    JComboBox comboBox = new JComboBox();

    setListCellRendererOf(comboBox);//www  .j a v a  2 s.c o m

    comboBox.addItem("A");
    comboBox.addItem("B");
    comboBox.addItem("C");

    getContentPane().add(comboBox, "North");
    setSize(200, 100);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:Main.java

public Main() {
    setPreferredSize(new Dimension(320, 240));
    setBackground(hue.getColor());/*w  ww  . j a  va 2  s.c o  m*/
    JComboBox colorBox = new JComboBox();
    for (Hue h : Hue.values()) {
        colorBox.addItem(h);
    }
    colorBox.addActionListener(e -> {
        Hue h = (Hue) colorBox.getSelectedItem();
        Main.this.setBackground(h.getColor());
    });
    this.add(colorBox);
}

From source file:Main.java

public Main() {
    JComboBox<String> comboBox = new JComboBox<String>();
    comboBox.setRenderer(new MyListCellRenderer());
    comboBox.addItem("Hi");
    comboBox.addItem("Hello");
    comboBox.addItem("How are you?");

    getContentPane().add(comboBox, "North");
    setSize(400, 300);/*from   w w w .  j  ava  2  s . c  om*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:Main.java

public Main() {
    JComboBox comboBox = new JComboBox();

    ((JLabel) comboBox.getRenderer()).setHorizontalAlignment(JLabel.RIGHT);

    comboBox.addItem("Apple");
    comboBox.addItem("Orange");
    comboBox.addItem("Mango");

    getContentPane().add(comboBox, "North");
    setSize(200, 100);//from   w ww  .java 2 s. c om
    this.setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:Main.java

private JComboBox createComboBox(final Map<Integer, Student> map) {
    final JComboBox cbox = new JComboBox();
    for (Integer id : map.keySet()) {
        cbox.addItem(id);
    }/*from ww  w  .  j  av  a2s.c o m*/

    cbox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Integer id = (Integer) cbox.getSelectedItem();
            System.out.println(map.get(id));
        }
    });

    return cbox;
}

From source file:org.jfree.chart.demo.DrawStringDemo.java

private void populateTextAnchorCombo(JComboBox jcombobox) {
    jcombobox.addItem("TextAnchor.TOP_LEFT");
    jcombobox.addItem("TextAnchor.TOP_CENTER");
    jcombobox.addItem("TextAnchor.TOP_RIGHT");
    jcombobox.addItem("TextAnchor.HALF_ASCENT_LEFT");
    jcombobox.addItem("TextAnchor.HALF_ASCENT_CENTER");
    jcombobox.addItem("TextAnchor.HALF_ASCENT_RIGHT");
    jcombobox.addItem("TextAnchor.CENTER_LEFT");
    jcombobox.addItem("TextAnchor.CENTER");
    jcombobox.addItem("TextAnchor.CENTER_RIGHT");
    jcombobox.addItem("TextAnchor.BASELINE_LEFT");
    jcombobox.addItem("TextAnchor.BASELINE_CENTER");
    jcombobox.addItem("TextAnchor.BASELINE_RIGHT");
    jcombobox.addItem("TextAnchor.BOTTOM_LEFT");
    jcombobox.addItem("TextAnchor.BOTTOM_CENTER");
    jcombobox.addItem("TextAnchor.BOTTOM_RIGHT");
}