File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JOptionPane confirmation dialog box functionality issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JOptionPane confirmation dialog box functionality issue" Watch "JOptionPane confirmation dialog box functionality issue" New topic
Author

JOptionPane confirmation dialog box functionality issue

Rajesh k Jha
Ranch Hand

Joined: May 10, 2009
Posts: 72
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
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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:

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
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.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Feb 23, 2007
Posts: 1561
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
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
Gee, doesn't anybody read my suggestions? I provided and explanation for the problem and the same solution (hours earlier).
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: May 10, 2009
Posts: 72
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JOptionPane confirmation dialog box functionality issue
 
Similar Threads
JOptionPane buttons
JOptionPane Dialog box - JOptionPane - Dialog box - not responding to Tab keys
Simple Message that doesn't require response from User?
How to create new dialog like JOptionPAne
JDialogBox