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.
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 ?
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 ]
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 ]
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.