Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox event order.  RSS feed

 
Jon Senior
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a little trouble with a JComboBox. Essentially I want to use it for a Yes/No situation (Within the GUI it's neater than a set of radio buttons), but I want the user to confirm the "Yes" option via a dialog box (as setting this option could be damaging).

Using either ActionPerformed or ItemStateChanged results in a dialog box popping up before the drop down list has disappeared. With the Swing L+F this results in the drop down box being drawn over the top of the dialog. In the System L+F (On Linux/Gnome) this results in the same plus it takes two clicks to clear the dialog.

The attached code is self-contained. It contains methods for handling both the actionPerformed and itemStateChange events (although the actionPerformed listener is commented out). The same behaviour exists with either.




java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) Server VM (build 20.0-b11, mixed mode)


Anyone else encountered this? Am I going to be forced to use radio buttons? Is there an event which is triggered after the drop down box has closed?

Thanks,

Jon
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I havent tried out your code but you can try wrapping the confirmation dialog inside SwingUtilities#invokeLater()
 
Jon Senior
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That got it. GUI stuff really isn't my forté. Thanks for that.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The general concept is to let the Swing subsystem finish doing whatever it was doing before taking up the new task you've assigned it.

I wish my boss would wrap his instructions in an invokeLater
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!