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

JOptionPane confirmation dialog box functionality issue

 
Rajesh k Jha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am just suprised when i checked the behaviour of JoptionPane confirm dialog box functionality.

Above code give us option to choose between Yes/No, When i choose the option using mouse it works fine, but when i use tab to move to the "No" option and press enter it is being treated like i have choosen "Yes" option.

I just want to know how to overcome this functionality so that whether i use mouse or Tab and then enter to choose the option.

Thanks in advance
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JOptionPane works fine, but something is wrong with your program, you've got a bug, but it's likely somewhere else in code that you're not showing us. For instance, this works:

 
Rob Camick
Ranch Hand
Posts: 2580
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe be a version/platform difference. It doesn't work for me either on XP using JDK6_7.

Check out Enter Key and Button for a solution.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doesn't work for me either, vista, 1.6.20something

you could also try adding this line (prior to creating optionPane)

UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:doesn't work for me either, vista, 1.6.20something

you could also try adding this line (prior to creating optionPane)

UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);


Shows what happens when I don't read the whole question! To the OP, please ignore my post!
 
Rob Camick
Ranch Hand
Posts: 2580
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gee, doesn't anybody read my suggestions? I provided and explanation for the problem and the same solution (hours earlier).
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Gee, doesn't anybody read my suggestions? ..

Oops, I clicked the link but didn't read the first part, just saw the Input Map stuff.
 
Rajesh k Jha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael,

I got my problem solved, hence i want to post this comment so that other can get benefit from this kind of problem.

What i simply did is used following code.



And its working fine for all the OptionPane.

Thanks once again
Rajesh Jha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic