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 = { "A", "A", "B", "B", "C", "C" }; JComboBox cb = new JComboBox(items); cb.setKeySelectionManager(new MyKeySelectionManager()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.setEditable(true);/*from w w w . java2 s . c o m*/ MyItemListener actionListener = new MyItemListener(); cb.addItemListener(actionListener); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "A", "A", "B", "B", "C" }; JComboBox cb = new JComboBox(items); cb.addKeyListener(new MyKeyListener()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.setEditable(true);/* w ww . j a v a2 s .c om*/ // Create and register listener MyActionListener actionListener = new MyActionListener(); cb.addActionListener(actionListener); }
From source file:Main.java
public static void main(String[] args) { String[] weekdays = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" }; final JComboBox<String> combo = new JComboBox<>(weekdays); String[] options = { "OK", "Cancel", "Help" }; String title = "Title"; int selection = JOptionPane.showOptionDialog(null, combo, title, JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (selection > 0) { System.out.println("selection is: " + options[selection]); }//ww w .j a v a 2 s . co m Object weekday = combo.getSelectedItem(); if (weekday != null) { System.out.println("weekday: " + weekday); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "A", "A", "B", "B", "C" }; JComboBox cb = new JComboBox(items); // Create and register the key listener cb.addKeyListener(new MyKeyListener()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.setEditable(true);/* w w w .j a v a 2 s.c om*/ MyPopupMenuListener actionListener = new MyPopupMenuListener(); cb.addPopupMenuListener(actionListener); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = new String[50]; for (int i = 0; i < items.length; i++) { items[i] = "" + Math.random(); }// w w w . jav a2 s . c om JComboBox cb = new JComboBox(items); // Retrieve the current max visible rows int maxVisibleRows = cb.getMaximumRowCount(); // Change the current max visible rows maxVisibleRows = 20; cb.setMaximumRowCount(maxVisibleRows); }
From source file:Main.java
public static void main(String[] args) { JFrame result = new JFrame(); JComboBox<String> combobox = new JComboBox<>(new String[] { "foo", "bar", "aaa", "Hello World" }); result.add(combobox, BorderLayout.CENTER); JCheckBox toggleVisibility = new JCheckBox("Toggle visibility"); toggleVisibility.setSelected(combobox.isVisible()); toggleVisibility.addItemListener(e -> { combobox.setVisible(e.getStateChange() == ItemEvent.SELECTED); });//w w w. j a v a2 s. c o m result.add(toggleVisibility, BorderLayout.SOUTH); result.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); result.pack(); result.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] items = { "A", "B", "C", "D" }; JComboBox<String> combo = new JComboBox<String>(items); combo.setEditable(true);/*from w ww . j av a 2 s .c om*/ removeButton(combo); JOptionPane.showMessageDialog(null, combo); }