Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane button selection  RSS feed

 
luke patte
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have code similar to that below, it all works fine when the user clicks the yes and no button, however when the user uses tab to select the button and presses enter to select the button, it doesn't perform as I want. I think maybe an extra event is produced, is this the case and how can I stop it??
int n = JOptionPane.showConfirmDialog(.....JOptionPane.YES_NO_OPTION)
if (n == JOptionPane.YES_OPTION) {
..........}
if(n == JOptionPane.NO_OPTION) {
............}
Cheers
luke
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just the default key bindings for the JOptionPane... ENTER presses the "default" button (which in this case is "YES"), spacebar presses the currently selected button.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!