It seems no selected or deselected ItemEvent
s are generated for the null-item in the JComboBox. How can I change this? Making the item ""
is not an option.
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
public class ComboBoxTest {
public static void main(String... args) {
JComboBox cb = new JComboBox(new String[]{null, "one","two","three"});
cb.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
System.out.println(e);
}
});
JOptionPane.showMessageDialog(null, cb);
}
}