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 int select(String[] selList, String msg) { JComboBox<String> box = new JComboBox<>(selList); Object msgs[] = new Object[2]; msgs[0] = msg;/* w ww. j a v a2 s . c o m*/ msgs[1] = box; int result = JOptionPane.showOptionDialog(null, msgs, msg, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.CANCEL_OPTION) return -1; return box.getSelectedIndex(); }
From source file:Main.java
public static JComboBox createStandardCombo(Object[] values) { JComboBox combo = new JComboBox(values); FontMetrics fm = combo.getFontMetrics(combo.getFont()); // combo.setPreferredSize(new Dimension(combo.getPreferredSize().width, fm.getHeight())); return combo; }
From source file:Main.java
public static <TYPE> JComboBox<TYPE> createComboBox(TYPE[] items, ActionListener... listeners) { JComboBox<TYPE> result = new JComboBox<>(items); for (ActionListener listener : listeners) { result.addActionListener(listener); }/* w ww.jav a 2s. c o m*/ return result; }
From source file:Main.java
public Main() { super();/*from w ww . j av a2s.c o m*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox jcb = new JComboBox(new String[] { "a", "b", "c", "d" }); getContentPane().add(jcb); setSize(200, 50); setVisible(true); }
From source file:Main.java
public Main() { JComboBox<String> cb = new JComboBox<>(new String[] { "a", "m", "b", "c", "v" }); cb.setSelectedIndex(-1);//from w ww. j a va 2s . c o m JButton button = new JButton("Print Selection"); button.addActionListener(e -> { if (cb.getSelectedIndex() != -1) System.out.println(cb.getSelectedItem()); else System.out.println("Not selected"); }); add(cb); add(button); }
From source file:Main.java
public Main() { super();//from w w w. j a v a 2 s. co m states = new JComboBox<String>(new String[] { "Select a State", "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY" }); setLayout(new FlowLayout(FlowLayout.CENTER)); add(states, BorderLayout.CENTER); states.addItemListener(e -> { if (states.getSelectedIndex() > 0) { System.out.println("YOU CLICK INDEX- " + states.getSelectedIndex()); } }); }
From source file:Main.java
public Main() { JComboBox itemsComboBox = new JComboBox(new String[] { "A", "L", "M" }); itemsComboBox.setEditable(true);/*from w ww . jav a 2 s . co m*/ itemsComboBox.setMaximumRowCount(3); this.getContentPane().add(itemsComboBox); itemsComboBox.setVisible(true); applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT); this.validate(); this.repaint(); }
From source file:JComboBoxDemo.java
public JComboBoxDemo() { JComboBox itemsComboBox = new JComboBox(new String[] { "A", "L", "M" }); itemsComboBox.setEditable(true);/* w ww.j av a 2 s . c o m*/ itemsComboBox.setMaximumRowCount(3); this.getContentPane().add(itemsComboBox); itemsComboBox.setVisible(true); applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT); this.validate(); this.repaint(); }
From source file:Main.java
Main(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector v = new Vector(); v.add("A");/*from w ww.j a va2s. co m*/ v.add("B"); v.add("C"); JComboBox jcb = new JComboBox(v); getContentPane().add(jcb); setSize(200, 50); setVisible(true); }
From source file:MainClass.java
MainClass(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector v = new Vector(); v.add("A");/*from ww w . jav a2 s . c o m*/ v.add("B"); v.add("C"); JComboBox jcb = new JComboBox(v); getContentPane().add(jcb); setSize(200, 50); setVisible(true); }