Results 1 to 3 of 3
  1. #1
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Default reseting text fields; .setText("") best option?

    Java Code:
    txtFirstName.setText("");

    Is there a way to reset all text fields within a container without doing each field individually with .setText("") ?

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

    Default

    One option: Put them in a List such as a LinkedList, and then iterate through the list calling setText("").
    Other option: getComponents from the Container, iterate through them testing for instanceof JTextField, and if matches, cast and setText("");
    Best option: ?
    Last edited by Fubarable; 02-23-2010 at 12:57 AM.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I think the first option is east to use, and safer since no casting is required. Not a real mess, but I like to avoid it in my applications as much as possible.

Similar Threads

  1. Metro WS apt option key="r"
    By Steve11235 in forum Advanced Java
    Replies: 3
    Last Post: 02-01-2010, 09:08 AM
  2. JAX-WS\METRO - apt with option option key="r"
    By Talkinjive in forum Web Frameworks
    Replies: 0
    Last Post: 01-31-2010, 04:15 PM
  3. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 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
  •