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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date