1. JComboBox.addItem for null objects stackoverflow.comHI, I have a JComboBox to which I'm adding my custom object items. But sometimes the object added are empty. So, when the comboBox has empty items in it, it collapses and ... |
2. Problems with JComboBox additem() method coderanch.comI dynamically build a user defined series of JComboBoxes via a loop. During the build i test if a certain condiion is true, if true I add an item to the JcomboBox currently being built. Problem is that when i add an item, i end up adding the new item to each box, 2 time. Hopefully fresher eyes can spot my ... |
3. How do you use JComboBox addItem(Object) coderanch.comsimple demo (in this name appears, click a name to get the value) import javax.swing.*; import java.awt.*; import java.awt.event.*; class Testing extends JFrame { Beer[] beers = {new Beer("Budweiser",1.50),new Beer("Millers",2.00), new Beer("Coors",5.00)}; JComboBox cbo = new JComboBox(beers); public Testing() { setLocation(400,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); cbo.setEditable(true); JPanel jp = new JPanel(); jp.add(cbo); getContentPane().add(jp); pack(); cbo.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ JOptionPane.showMessageDialog(getContentPane(),"Value = "+((Beer)cbo.getSelectedItem()).value); } ... |