0

I'm using a JComboBox that triggers the opening of another frame if the item selected is changed.

Here is an example of code.

String[] liste = {"Stack", "Over", "Flow"};
JComboBox comboBox = new JComboBox(liste);
comboBox.addItemListener(e -> {
    if(e.getStateChange() == 2) { //because that listener is called twice, when the item is unselected and the new is selected
        FramePopUp popUp1 = new FramePopUp(); //Class that extends JFrame
    }
});

My issue is that I want this Frame to be triggered too when the user select twice the same item.

For example:

The user selects in this case the item "Over", the Frame Pop's up, the user deal with the Frame and the informations he have to give and then close the Frame.

He remembered that he forgot to fill one information, so he re-select the item "Over" but nothing happens because he did not change the selected item.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 3) Please use code formatting for code and code snippets, structured documents like HTML/XML or input/output. To do that, select the text and click the `{}` button at the top of the message posting/editing form. – Andrew Thompson Mar 29 '19 at 15:47

1 Answers1

2

Just add an ActionListener instead of an ItemListener.

see also JCombobox - Only execute actionlistener when value changes where someone had the opposite problem from you

ChristophE
  • 760
  • 1
  • 9
  • 21