Problems with default button...

Hello,

I have some problems concerning the default button.

MyJDialog which is called from within my application (JFrame) sets the default button ininitComponents() (called by the constructor):

getRootPane().setDefaultButton(jButton1);

When opening the dialog for the first time everything works... which means pressing enter invokes the default button - but when opening the dialog again pressing enter doesn't invoke the default button (nothing happens).

TheJDialog is created only once - future calls to open the dialog use

myDialog.setVisible(true);

to display it.

Another point is when I open the dialog for the second time for example, the recent search results are displayed (my dialog contains aJTable with search results the user can select from) and the row which was selected by the user is highlighted (selected) - is that what causes the problem?

Any help would be greatly appreciated

- Stephan

[1046 byte] By [Jacklera] at [2007-11-27 9:39:17]
# 1

If the component that has focus handle the Enter key press then it will have priority over the default button. So if focus is on the table the enter key will probably move you down to the next line.

Read up on how "Key Bindings" work:

http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html

camickra at 2007-7-12 23:14:16 > top of Java-index,Desktop,Core GUI APIs...