Hello,
I have a problem setting a default button with Java Swing.
I have a JFrame containing one JPanel and one JMenuBar. This panel contains some textfields,
a list and some buttons. At the button there is one button which has to be the default
button. I also gave the JPanel a method getDefaultButton which returns the button which
I want to be the Default Button. So in the contructor of the JFrame I wrote:
getRootPane().setDefaultButton(panel.getDefaultButton());
This works all correct, but I also want that in one case (If the focus belongs to a certain
textfield) there is a different default button. So I wrote a KeyListener for this textfield
and implemented the method KeyReleased like this:
public void keyReleased(KeyEvent evt) {
if(evt.isActionKey())
btnSelect.doClick();
}
When the focus belongs to this textfield and I press enter the
default button is still executed. Is their anonther way to solve this problem?
Thanks in advance