This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

default button for view, eg ENTER in login

Aug 11th, 2005, 12:28 PM

Hi all,

Anyone any ideas on how to retrieve the root Frame of the application?
I want to set a default button for a view but cant get hold of the root frame to set that button, eg a login screen with a default "login" button

I could always add listeners but would like to keep it simple...

Rootpane always a null, so rfame seems to be?, and on focusgained seems like the only place where i could set a default button for a screen.

I don't wan't to open a new thread about this topic. Sometimes it is necessary to enable the RETURN key to commit the form. In order to achieve this, I remove the default button in my TitledApplicationDialog like this:

Code:

getDialog().getRootPane().setDefaultButton(null);

it works fine, but an interesting phenomenon occurs when I open the dialog. The dialog is shown on the top left corner. If i don't remove the default button, the dialog will be centered.

Any ideas?

markus

Comment

This sounds like your code causes something that has an impact on the call of setLocationRelativeTo(parent) in the ApplicationDialog class. If the setLocationRelativeTo() is called and parent is null, the dialog is displayed centered on screen ... if not it is displayed relative to the parent component.
But maybe another hint could help you: If you look at the addCancelByEscapeKey() method in the ApplicationDialog class you should be able to register the ENTER key for the finish command and you must no longer set the default button to null.

I haven't tested this .... but I hope it helps with your problem.

cheers,
Andi

Comment

thanks for the hint. I've also tried to remove the RETURN key from the input map, which is generated by ApplicationDialog. But in Swing a default button is automatically associated with the RETURN key.