Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: AWT
Expertise: Beginner
Mar 31, 1998

Default button

Question:
How can I implement a "default" button in a window?

Answer:
You can explicitly request the focus using requestFocus(), but the button can still lose the focus. Therefore you have to extend your containing component and trap all keyboard events, passing them to your default button. At least that's what you had to do before the Swing classes came along. If you are using the Swing classes (highly recommended), all you have to do is call setDefaultButton() in JRootPane to set the default button for a window. In other words, get the root pane of a JWindow with getRootPane(), and then call setDefaultButton() with your button as the argument.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date