Hi all I am having some difficulties with adding a joptionpane in JcheckBox listener
public void itemStateChanged(ItemEvent evt) {
if(evt.getStateChange() == ItemEvent.SELECTED){
///some code
JOptionPane.showMessageDialog(null, "Message", "Alert",
JOptionPane.INFORMATION_MESSAGE);
}
}
so it works fine,but the problem is that the JCheckBox gets selected and immediately deselected how can I manage to fix this ?
Cheers
There are a couple of suggestions here (solution) to use an action listener instead of a item listener. This does work, however, I though it strange given that all the texts I have suggest an item listener is the expected type of listener for a check box.
In fact, this is a known bug as acknowledged by Oracle Bug ID:6924233 The JOptionPane apparently causes another event to be generated.
The recommended fix is to invoke the JOptionPane using invokeLater. This works fine and involves only a minor code change to a program already using an item listener for other purposes.