Results 1 to 7 of 7
  1. #1
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Post Make multiple JTextFields focus at the same time.

    Hey guys,

    This is my first time working with Swing and i'm using the gui builder in Netbeans 6.7. Basically i'm having a user enter a number on a JOptionPane and then I have a gui that appears and has 6 JTextFields. I'm querying a database to pull information to populate these 6 JTextFields.

    My problem is that I can only make one field focus at a time. If i click on each field one by one they populate. Is there a way to make all of the JTextFields focus at the same time so they all display the values?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    How are you populating them?

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    Java Code:
    textField1.setText(...);
    textField2.setText(...);
    ...
    panel.add( textField1 );
    panel.add( textField2 );
    ...
    panel.revalidate();
    panel.repaint();

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I don't understand your question as the JTextFields don't need to have focus to display values. You just set their text via the setText(...) method.

  5. #5
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

    Default

    Well on my gui there are 5 text fields and in the design mode in netbeans I clicked on the first text field and then in the properties you go to the events tab. Under focus gained, I clicked the dots to create a handler. I figured out that I only need the focus gained handler for the first text field and I can do a textField.setText(); for all of the text fields in that one handler.

    I thought I would have had to set the text in each of their own handlers. Thanks for your help though.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    NetBeans tries to protect you from the underpinnings of Swing, but in doing so, can hinder the learning of Swing. To learn how to use JTextFields, I suggest that you put the NetBeans code generation aside for a little bit, and go through the Sun Swing tutorial. You won't regret doing this.

    You really don't want to set the text on focus-gained and in fact usually don't do it this way. You'll want to set the text by calling setText(...) on the JTextField in response to some event (which event will depend on your program). Again, the Swing tutorials will show you the way.

  7. #7
    toymachiner62 is offline Member
    Join Date
    Oct 2009
    Posts
    63
    Rep Power
    0

Similar Threads

  1. Class Time - represents time of day
    By verbazon in forum New To Java
    Replies: 1
    Last Post: 04-13-2009, 01:06 AM
  2. Replies: 1
    Last Post: 07-03-2008, 01:05 PM
  3. Problem with JTextFields not null
    By romina in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:17 AM
  4. JTextFields with username & password.
    By Eric in forum AWT / Swing
    Replies: 2
    Last Post: 07-01-2007, 11:41 PM

Posting Permissions

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