List of usage examples for javax.swing JComboBox JComboBox
public JComboBox(Vector<E> items)
JComboBox
that contains the elements in the specified Vector. From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); // Add an item to the start of the list cb.insertItemAt("item0", 0); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.insertItemAt("item0.5", 1); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); // Determine if the menu is visible boolean isVisible = cb.isPopupVisible(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); Object obj = cb.getSelectedItem(); cb.setSelectedItem("item2"); obj = cb.getSelectedItem();/*from w ww.ja v a 2 s. c o m*/ cb.setSelectedItem("item3"); obj = cb.getSelectedItem(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2", "item3" }; JComboBox cb = new JComboBox(items); // Get number of items int num = cb.getItemCount(); // Get items/*from w ww. java2s.c o m*/ for (int i = 0; i < num; i++) { Object item = cb.getItemAt(i); } }
From source file:Main.java
public static void main(String argv[]) throws Exception { JComboBox<Item> comboBox = new JComboBox<Item>( new Item[] { new Item("Major", "red"), new Item("Critical", "dark"), new Item("Minor", "green") }); comboBox.addActionListener(e -> { JComboBox<Item> combo = (JComboBox<Item>) e.getSource(); Item item = (Item) combo.getSelectedItem(); System.out.println(item.getColor()); });/* w w w. java 2 s. c om*/ JFrame frame = new JFrame(); frame.add(comboBox); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public static void main(String[] args) { JComboBox<Country> countryBox = new JComboBox<Country>(Country.values()); JOptionPane.showMessageDialog(null, new JScrollPane(countryBox)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Create a read-only combobox String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.setEditable(true);//from ww w . j a v a2 s . c o m cb.setSelectedItem("item3"); Object obj = cb.getSelectedItem(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Create a read-only combobox String[] items = { "item1", "item2" }; JComboBox readOnlyCB = new JComboBox(items); // Create an editable combobox items = new String[] { "item1", "item2" }; JComboBox editableCB = new JComboBox(items); editableCB.setEditable(true);/* w w w .jav a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { Object[] options = { "Option 1", "Option 2", "Option 3", "None of the above" }; JComboBox optionControl = new JComboBox(options); optionControl.setSelectedIndex(3);//from w ww. j a va2 s . c om JOptionPane.showMessageDialog(null, optionControl, "Option", JOptionPane.QUESTION_MESSAGE); System.out.println(optionControl.getSelectedItem()); String graphSelection = (String) JOptionPane.showInputDialog(null, "Choose from the following options...", "Choose From DropDown", JOptionPane.QUESTION_MESSAGE, null, options, options[3]); System.out.println(graphSelection); JOptionPane.showMessageDialog(null, optionControl, "Option", JOptionPane.QUESTION_MESSAGE); }