• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing default buttons in JOptionPane  RSS feed

 
Greg Jewell
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I've had a request from a user to change the behavior of a JOptionPane. He likes to tab through choices in the pane, but tends to press enter rather than space when the choice that he wants has focus. How can I change the JOptionPane so that the default button follows the focus?
I'm currently displaying the pane using the JOptionPane.showConfirmDialog(..) method.

Thanks,
Greg Jewell
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like you are going to have to subclass JOptionPane and set it up to be keylistener to the buttons and listen for the enter key. If you did that, you *might* be able to still use the showConfirmDialog() from your new subclass without any extra code. Worst case is you would have to overwrite the static showConfirmDialog() method. Just copy and paste it from JOptionPane and make sure it calls an instance of you subclass instead of the original.
hth
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!