when i am pressing the complain box, each input dialog is displaying twice...i tried removing the boxComplain.setSelected(true) and it worked (it displayed only once) but that made the checkbox go after i enter the input.
class CheckBoxListener implements ItemListener {
public void itemStateChanged(ItemEvent event) {
if(boxComplain.isSelected())
{
ab=JOptionPane.showInputDialog("Enter Reason of Complain: ");
ac=JOptionPane.showInputDialog("Enter What The Complain is About: ");
label4.setText("Complain request");
boxComplain.setSelected(true);
}
}
}
The ItemListener is called twice -- once when the original selection has been changed, and 2nd time when the new selection is registered. Consider using an ActionListener instead.
Another trick is to remove and add the ItemListener:
public void itemStateChanged(ItemEvent event) {
if(boxComplain.isSelected()) {
ab=JOptionPane.showInputDialog("Enter Reason of Complain: ");
ac=JOptionPane.showInputDialog("Enter What The Complain is About: ");
label4.setText("Complain request");
boxComplain.removeItemListener(this);
boxComplain.setSelected(true);
boxComplain.addItemListener(this);
}
}