Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-01-2007, 07:31 PM
Member
 
Join Date: Jun 2007
Location: Colombo, Sri Lanka
Posts: 32
hiranya is on a distinguished road
Default Button
Hi everyone,

I want to make a JButton object on a JFrame to be the default button for the form. That means the button should be always selected by default and when the user hits 'enter' the button should be activated (pressed).

Any idea how to achieve this?

Thanks

Regards
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-01-2007, 07:39 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
The concept you need to use is Focus. Check the following tutorial for details:

Focus on Swing - Java World

And check the following tip for a quick solution:

Setting the Initial Focused Component in a Window - Java Almanac - jug.ORG.ua Wiki
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-01-2007, 08:08 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Code:
JRootPane rootPane = topLevelContainer.getRootPane(); rootPane.setDefaultButton(myJButton);
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting the default browser+MIME data waleed_cs2000 Networking 1 04-08-2008 03:31 PM
Printing default Swing values Java Tip Java Tips 0 03-12-2008 01:09 PM
How to change the default Java integrator New To Java 4 02-01-2008 05:19 PM
Connecting to a Website with the default browser Riftwalker Java Applets 4 12-04-2007 06:57 PM
How can I make the file ALWAYS save as .txt by default paul AWT / Swing 1 08-07-2007 07:09 AM


All times are GMT +3. The time now is 02:55 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org