Results 1 to 7 of 7
  1. #1
    dougie1809 is offline Senior Member
    Join Date
    Nov 2011
    Posts
    116
    Rep Power
    0

    Default JTextField Question.

    Hi,

    If you have a JTextField with a setText("Enter name here: "), what class and/or method can I use so when I click on that JTextField, it removes that String in the setText method? Instead of having to manually backspacing 'Enter name here:' all the time?
    Thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: JTextField Question.

    MouseListener? FocusListener? CaretListener?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: JTextField Question.

    Or use camickr's Text Prompt Java Tips Weblog

    Moving to AWT/Swing

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    dougie1809 is offline Senior Member
    Join Date
    Nov 2011
    Posts
    116
    Rep Power
    0

    Default Re: JTextField Question.

    Thanks guys that worked

  5. #5
    Join Date
    Apr 2012
    Location
    Long Island, NY
    Posts
    6
    Rep Power
    0

    Default Re: JTextField Question.

    In netbeans you can set the action mouseClicked and inside of that put something like jTextField.setText(null);

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

    Default Re: JTextField Question.

    Quote Originally Posted by cristian.rivera View Post
    In netbeans you can set the action mouseClicked and inside of that put something like jTextField.setText(null);
    Not good, because what if they arrive in the field via tab key press? Much better to use a FocusListener and to not set the text to null but to "".

  7. #7
    Join Date
    Apr 2012
    Location
    Long Island, NY
    Posts
    6
    Rep Power
    0

    Default Re: JTextField Question.

    Quote Originally Posted by Fubarable View Post
    Not good, because what if they arrive in the field via tab key press? Much better to use a FocusListener and to not set the text to null but to "".
    Thats true, i didn't think about that

Similar Threads

  1. newbie jtextfield question
    By Danieldcc in forum New To Java
    Replies: 7
    Last Post: 12-24-2011, 12:33 AM
  2. JTextfield question
    By xyknight in forum New To Java
    Replies: 3
    Last Post: 04-08-2011, 04:25 PM
  3. JTextField Question
    By Rocketz in forum New To Java
    Replies: 1
    Last Post: 03-09-2011, 12:38 AM
  4. JTextField Question
    By Kyle227 in forum New To Java
    Replies: 5
    Last Post: 05-09-2010, 07:44 AM
  5. JTextField question
    By Chasingxsuns in forum New To Java
    Replies: 5
    Last Post: 07-14-2009, 02:39 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
  •