Results 1 to 3 of 3

Thread: Default Button

  1. #1
    hiranya is offline Member
    Join Date
    Jun 2007
    Location
    Colombo, Sri Lanka
    Posts
    32
    Rep Power
    0

    Question 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

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    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

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    JRootPane rootPane = topLevelContainer.getRootPane();
    rootPane.setDefaultButton(myJButton);

Similar Threads

  1. getting the default browser+MIME data
    By waleed_cs2000 in forum Networking
    Replies: 1
    Last Post: 04-08-2008, 01:31 PM
  2. Printing default Swing values
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 11:09 AM
  3. How to change the default Java
    By integrator in forum New To Java
    Replies: 4
    Last Post: 02-01-2008, 03:19 PM
  4. Connecting to a Website with the default browser
    By Riftwalker in forum Java Applets
    Replies: 4
    Last Post: 12-04-2007, 04:57 PM
  5. Replies: 1
    Last Post: 08-07-2007, 05:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •