Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JOptionPane.showConfirmDialog question

 
Ben Zung
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the following code. When run, expected behavior is when "Yes" is selected, 0 returned. when "No" is selected 1 is returned. I found it pretty odd that above is true when you use mouse. It is not true when you use the keys. After you see the confirmation dialog, hit tab to move focus
to "No" and hit enter, you get output of 0. Same thing happens when you use the ALT+N combination.
Could anyone help me out this?
Thanks
Here is the code:
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, let me preampt this with I don't know why this is, but it is...
The ENTER key will push the Default button no matter what. On a JPOptionPane the default Button is the OK or YES button.
Pressing the Space Bar on the focused Button will do what you want.
Also, ALT-N worked just fine for me. I got the desired result of 1 when I did an ALT-N and ALT-Y returned 0.
 
maggie woo
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the look and feel--Windows look and feel does what you expect...
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by maggie woo:
Depends on the look and feel--Windows look and feel does what you expect...


Good to know maggie. Thanks.
 
Ben Zung
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Both of you.
That's very helpful.
The ENTER key will push the Default button no matter what. On a JPOptionPane the default Button is the OK or YES button.

Did not know that. Browsed the API and may have missed it.
Have a good one.
Bing
 
maggie woo
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:

Good to know maggie. Thanks.

Sure thing! But as always, the answer to the question may not be the same as the solution to the problem. We played around with making our apps use WindowsLookAndFeel, and it made the app about as unstable as any other Windows app, so we stopped using it. Perhaps they were a little too true to the look and particularly the "feel" of that PLAF.
 
Ben Zung
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why I endup writing my own ConfirmDialog to avoid explicitly specify any look and feel
Bing
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic