• Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane and the default focus  RSS feed

 
gautham kasinath
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All!
Well, when you have a JOptionPane displaying a message with an OK and Cancel button, how do you get the focus to the cancel button, by default, instead of the OK button??
Well, if you are telling me to do a requestfocus.. please understand that a simple requestfocus did not work.
Please reply asap.
Regds
Lupo
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a code example that shows how to change the default button selected... you can use it to figure out what you want to do... especially look at the LaunchListener...

 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this works, as well:

Chantal
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ack!

Chantel's answer is much better than mine...
 
Skip Cole
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for this answer!!!

Its the little things, like having the focus on the button that cancel's and not on the one that can cause problems, that make an app look professional. Thanks a lot for Sharing!

Skip
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!