Results 1 to 8 of 8
  1. #1
    turc0033 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default Issue with obtaining data from the JTextField when JButton is pressed

    I have a JTextField (name), and a JButton (btnOK). When i type something into "name", and press enter, i can display the text using System.out.println(name);

    But when select "btnOK" after writing something to "name", it won't display the contents of "name". Is there a simple explanation to this, or do you guys guys want to see some code.

    Thanks in advance

  2. #2
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Did you add an action listener to the btnOK ?

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

    Default

    Without code, I think that there's no way on heaven or earth we can guess what you're doing wrong. Please be sure to use code tags, and optimally you should create and post an SSCCE. Please read the link to find out what is involved with that but briefly you'd be creating a small version of your code that compiles and runs and demonstrates your error.

  4. #4
    turc0033 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default

    Yes I did. Ill post some code up in a bit

  5. #5
    turc0033 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default

    Figured it out guys. Thanks. i was trying to access the information from a different panel

  6. #6
    Maxideon is offline Member
    Join Date
    Jun 2010
    Posts
    28
    Rep Power
    0

    Default

    A little known fact: you can add an ActionListener to a JTextField. The action performed method is called when you hit the enter key.

  7. #7
    turc0033 is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default

    Yep. But that's not going to get all 6 jtextfields at once.

  8. #8
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    No,
    you can get all 6 Jtextfield text at once or one button click, even if it is on different panels.

    -Regards

Similar Threads

  1. JButton with Icon & text alignment issue
    By ShardaD in forum AWT / Swing
    Replies: 4
    Last Post: 01-11-2011, 12:10 PM
  2. Highlight JTextField using Jbutton?
    By goffy in forum New To Java
    Replies: 11
    Last Post: 05-02-2010, 12:41 PM
  3. JXL, Numeric data issue
    By only2008 in forum Java Servlet
    Replies: 0
    Last Post: 02-27-2009, 12:36 PM
  4. [SOLVED] JtextField alignments issue.......?
    By prabhurangan in forum AWT / Swing
    Replies: 2
    Last Post: 06-19-2008, 09:50 AM
  5. Replies: 2
    Last Post: 03-30-2008, 09:38 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
  •