• Post Reply Bookmark Topic Watch Topic
  • New Topic

JCheckBox and ItemListener

 
Markus Schmider
Ranch Hand
Posts: 137
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to learn Swing for a project.
I have tried the following code from a tutorial. It does not work like I expected. When I click the checkbox, I get both MessageDialogs.
After I cofirm both, the checkbox is still unchecked.
What is going on here?

 
Tony Docherty
Saloon Keeper
Posts: 3143
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why this is happening but by displaying the JOptionPane from within the listener the checkbox is being deselected which is why you get the second JOptionPane being displayed. You can get around this by wrapping the code to display the JOptionPane in a Runnable and putting it onto the Event Queue to be invoked later. eg:


Hopefully someone else can give an explanation as to why this occurs and we can both learn something.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!