• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

JOptionPane button selection

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic