Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JOptionPane confirmation dialog box functionality issue

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am just suprised when i checked the behaviour of JoptionPane confirm dialog box functionality.

Above code give us option to choose between Yes/No, When i choose the option using mouse it works fine, but when i use tab to move to the "No" option and press enter it is being treated like i have choosen "Yes" option.

I just want to know how to overcome this functionality so that whether i use mouse or Tab and then enter to choose the option.

Thanks in advance
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JOptionPane works fine, but something is wrong with your program, you've got a bug, but it's likely somewhere else in code that you're not showing us. For instance, this works:

 
Rancher
Posts: 3262
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe be a version/platform difference. It doesn't work for me either on XP using JDK6_7.

Check out Enter Key and Button for a solution.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
doesn't work for me either, vista, 1.6.20something

you could also try adding this line (prior to creating optionPane)

UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Dunn wrote:doesn't work for me either, vista, 1.6.20something

you could also try adding this line (prior to creating optionPane)

UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);



Shows what happens when I don't read the whole question! To the OP, please ignore my post!
 
Rob Camick
Rancher
Posts: 3262
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gee, doesn't anybody read my suggestions? I provided and explanation for the problem and the same solution (hours earlier).
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Gee, doesn't anybody read my suggestions? ..

Oops, I clicked the link but didn't read the first part, just saw the Input Map stuff.
 
Rajesh k Jha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael,

I got my problem solved, hence i want to post this comment so that other can get benefit from this kind of problem.

What i simply did is used following code.



And its working fine for all the OptionPane.

Thanks once again
Rajesh Jha
 
A teeny tiny vulgar attempt to get you to buy our stuff
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic