aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JDialogBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDialogBox" Watch "JDialogBox" New topic
Author

JDialogBox

Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
Hi all,
I am very much new to swing and awt. I have a simple problem with my dialog box. (JDialogBox.showErrorMessage(....)) I am using dialog box to pop-up error messages. but when the user uses mouse to click on yes or no then even is generated correctly, but when the user hit enter key after focusing on NO , still it is generating the event for YES. something wrong with my implementation ? or this is expected result ? plz help me.
Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
hi
maybe there is something wrong with the events ..maybe there is no keyboard event for the no button,,check the events again
Good luck
Maha
Mahesh x Bogadi
Ranch Hand

Joined: Jul 06, 2004
Posts: 51
To show error / warning messages use JOptionPane.
They are helpful,
No need to create you own Dialog
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
Yes, I was talking about the JOptionPane only. when I used the JOptionPane to pop up error message that is taking Yes value when I hit enter even if the focus is set on No. I did not create any DialogBox my own, I just used JOptionPane to popup a message. I did not add any event for it. JOptionPane is responding perfeclty when I use mouse click, even when I use space also it is responding correctly. But when I hit enter key it is giving only the Yes value even if the focus in set on No. This is what the problem is, any idea ?
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
I was talking about this code fragment.


This is returning same value on Enter Key regardless of the focus. But in the mouse click it is returning the correct value. Please give your valuable comments.
[ August 18, 2005: Message edited by: Sanju Thomas ]
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
Please some one help me.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
In the app below the 'enter' key always seems to invoke the option that is the
'initialValue' in the dialog, ie, the button that is initially selected. This only seems to
work for the metal plaf. The option designated as the 'initialValue' in the constructor seems
to function like a default command button for the dialog. See paragraph four and Table 8
under the 'Keyboard Navigation and Activation' section of page 6 in the
'Java Look and Feel Guidelines'. Also the 'Default Command Buttons' section on
page 8.

ps — try using the 'spacebar' to activate the buttons instead of the 'enter' key.
[ August 19, 2005: Message edited by: Craig Wood ]
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
Thank you Craig, but Craig, is there any way to override this feature.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
is this what you're trying to do?

Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
Craig , Thank you for replay .

I was aware that it will work with Window look and feel, but I was asking that is there any way to get this feature in metal look and feel.

if there is some solution please send me a replay.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The defaultButton behavior seems to come from one or two places in the
javax.swing.plaf.basic.BasicOptionPaneUI class. The block under the
"counter == initialIndex" test adds an AncestorListener to the first JButton which sets it
as the defaultButton each time the button is made visible. I could not find a way to
remove/prevent the resulting action.

This minimal subclass of BasicOptionPaneUI seems to avoid the defaultButton issue. I tried
to map the "Enter" key to the optionPane JButtons to work like they do with the "Space"
bar/key. Seems to work okay so far.
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
Thanks Craig, I could not give a test on it, bcz my machine is loaded with 1.4, I can't change in this point bcz project is on the last phase. I will test it and give my update.

Thank you very much for spending some time for me.
 
Don't get me started about those stupid light bulbs.
 
subject: JDialogBox