Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Is there a way to clear a java text field in a GUI?

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    64
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Default Is there a way to clear a java text field in a GUI?

    Let's say the user types something into the JTextField.

    I want to retrieve it.

    I make an action listener, etc, so the user types something in, clicks "submit", and I take in what they wrote from the JTextField.

    Now, after they submit, I kind of want all the text fields to become empty again.

    How do I do that? I looked at the JTextField API but there didn't seem to be any methods that erase a text field. What should I do?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,742
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Is there a way to clear a java text field in a GUI?

    A significant part of programming is imagination to imagine the possible. There may not be a method to empty a JTextField, but there's certainly a method to set it to a String, and you've certainly heard of or come across the concept of an empty string, ' "" ', so put the two together, and what do you have?

  3. The Following 3 Users Say Thank You to GregBrannon For This Useful Post:

    andbin (December 13th, 2013), copeg (December 12th, 2013), ineedahero (December 12th, 2013)

  4. #3
    Member
    Join Date
    Sep 2013
    Posts
    64
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Default Re: Is there a way to clear a java text field in a GUI?

    Yup, that makes sense. Thanks!

Similar Threads

  1. How to create a Right Click Menu for a Text Field in Java?
    By deamon0 in forum AWT / Java Swing
    Replies: 1
    Last Post: July 18th, 2013, 11:20 PM
  2. Replies: 1
    Last Post: May 18th, 2013, 11:28 PM
  3. validating java text field
    By payal in forum AWT / Java Swing
    Replies: 1
    Last Post: July 24th, 2012, 12:41 AM
  4. Parsing from a GUI text field
    By jdubicki in forum AWT / Java Swing
    Replies: 6
    Last Post: May 17th, 2012, 03:46 PM
  5. Tic Tac Toe Java Application Help w/ Importing Text Field
    By Big Bundy in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 30th, 2011, 02:08 AM