List of usage examples for javax.swing DefaultComboBoxModel DefaultComboBoxModel
public DefaultComboBoxModel(Vector<E> v)
From source file:SharedDataSample.java
public static void main(String args[]) { final String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; final DefaultComboBoxModel model = new DefaultComboBoxModel(labels); JFrame frame = new JFrame("Shared Data"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JPanel panel = new JPanel(); JComboBox comboBox1 = new JComboBox(model); comboBox1.setMaximumRowCount(5);/*from ww w . j av a2s.co m*/ comboBox1.setEditable(true); JComboBox comboBox2 = new JComboBox(model); comboBox2.setMaximumRowCount(5); comboBox2.setEditable(true); panel.add(comboBox1); panel.add(comboBox2); contentPane.add(panel, BorderLayout.NORTH); JList jlist = new JList(model); JScrollPane scrollPane = new JScrollPane(jlist); contentPane.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Add"); contentPane.add(button, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int index = (int) (Math.random() * labels.length); model.addElement(labels[index]); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JComboBox<Object> combo = new JComboBox<>(); URL url = new Main().getClass().getResource("animated.gif"); combo.setModel(new DefaultComboBoxModel(new Object[] { makeImageIcon(url, combo, 0) })); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(combo);//from ww w . java2 s . c o m f.setSize(320, 240); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new GridLayout(0, 1, 5, 5)); String[] speciesName = { "1", "2", "3" }; String[][] breedName = { { "A", "P", "A" }, { "B", "P", "S" }, { "DDo", "A", "P" } }; JComboBox<String> petSpecies = new JComboBox<>(speciesName); JComboBox<String> petBreed = new JComboBox<>(); petSpecies.addItemListener(e -> { int ii = petSpecies.getSelectedIndex(); ComboBoxModel cbm = new DefaultComboBoxModel(breedName[ii]); petBreed.setModel(cbm);/*from w ww. j a va 2 s. c o m*/ petBreed.requestFocusInWindow(); }); gui.add(petSpecies); gui.add(petBreed); JOptionPane.showMessageDialog(null, gui); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Popup Menu Listener"); Container contentPane = frame.getContentPane(); final String flavors[] = { "Item 1", "Item 2", "Item 3" }; PopupMenuListener listener = new PopupMenuListener() { boolean initialized = false; public void popupMenuCanceled(PopupMenuEvent e) { }//from w ww. j a va 2s .c om public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } public void popupMenuWillBecomeVisible(PopupMenuEvent e) { if (!initialized) { JComboBox combo = (JComboBox) e.getSource(); ComboBoxModel model = new DefaultComboBoxModel(flavors); combo.setModel(model); initialized = true; } } }; JComboBox jc = new JComboBox(); jc.addPopupMenuListener(listener); jc.setMaximumRowCount(4); jc.setEditable(true); contentPane.add(jc, BorderLayout.NORTH); frame.pack(); frame.setVisible(true); }
From source file:PopupTest.java
public static void main(String args[]) { JFrame frame = new JFrame("Popup Menu Listener"); Container contentPane = frame.getContentPane(); final String flavors[] = { "Item 1", "Item 2", "Item 3" }; PopupMenuListener listener = new PopupMenuListener() { boolean initialized = false; public void popupMenuCanceled(PopupMenuEvent e) { }//from www. j av a 2 s .c o m public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } public void popupMenuWillBecomeVisible(PopupMenuEvent e) { if (!initialized) { JComboBox combo = (JComboBox) e.getSource(); ComboBoxModel model = new DefaultComboBoxModel(flavors); combo.setModel(model); initialized = true; } } }; JComboBox jc = new JComboBox(); jc.addPopupMenuListener(listener); jc.setMaximumRowCount(4); jc.setEditable(true); contentPane.add(jc, BorderLayout.NORTH); frame.pack(); frame.show(); }
From source file:Main.java
public Main() { setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jComboBox1 = new JComboBox(); jComboBox1.setModel(new DefaultComboBoxModel(new String[] { "1", "2" })); jComboBox1.addItemListener(evt -> { if (jComboBox1.isPopupVisible()) { jComboBox1.setPopupVisible(false); fireTask(evt);/*from w w w . ja v a2 s. c o m*/ } }); add(jComboBox1); pack(); }
From source file:Main.java
public Main() { models[0] = new DefaultComboBoxModel<>(new String[] { "A1", "A2" }); models[1] = new DefaultComboBoxModel<>(new String[] { "B1", "B2", "B3", "B4" }); models[2] = new DefaultComboBoxModel<>(new String[] { "C1", "C2" }); combo2.setModel(models[0]);//from w w w . j a v a 2s . c o m this.add(combo1); this.add(combo2); combo1.addActionListener(this); }
From source file:Main.java
public Main() { setLayout(new GridLayout(0, 1)); DefaultComboBoxModel<ComboColor> cModel = new DefaultComboBoxModel<>(ComboColor.values()); JComboBox<ComboColor> combo = new JComboBox<>(cModel); add(createComboLabelPanel(1, combo)); comboList.add(combo);//w ww . j ava 2 s . com }
From source file:net.landora.video.utils.UIUtils.java
public static ComboBoxModel generateComboModel(List<?> parametersFor) { DefaultComboBoxModel model = new DefaultComboBoxModel(parametersFor.toArray()); return model; }
From source file:rhinova.gui.dataentry.link.LinkDataEntryPanel.java
@SuppressWarnings("unchecked") @Override/*from w w w. j ava 2 s. c o m*/ public void onApplicationEvent(ReserveListUpdateEvent arg0) { this.res1.setModel(new DefaultComboBoxModel(arg0.getReserveIDs().toArray())); this.res2.setModel(new DefaultComboBoxModel(arg0.getReserveIDs().toArray())); }