• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

JOptionPane button selection

 
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!