Results 1 to 7 of 7
  1. #1
    nadia.ahmed is offline Member
    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Unhappy how to clear Multiple text fields ? please help

    hi i am new to programming and learning java please help me
    i have a form and it contain 8 different panels and all contains JtextField in this form there is almost 90 JtextFields
    i have button clear in the form all i want is to clear the all the fields when i press clear button
    i search and read articles on other site and also got some code but it is not working
    so i also tried to write my code still does not work please help i need to submit my assignment i am stuck in this only
    code for reset field is
    public static void resetTextFields(Container c) {
    Component [] components = c.getComponents();
    for (int i = 0; i < components.length; i++ ) {
    if (components[i] instanceof Container)
    resetTextFields((Container) components[i]) ;
    else
    if (components[i] instanceof JTextField)
    ((JTextField) components[i]).setText("") ;
    }
    }
    button i am calling is

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:

    resetTextFields(this);

    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,335
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to clear Multiple text fields ? please help

    Look at the class hierarchy for the Swing JComponents; every JComponent (e.g. a JTextField) is a Container itself. So in that loop first test whether or not the Component is a JTextField; next test if it is a Container.

    kind regards

    Jo
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    nadia.ahmed is offline Member
    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Default Re: how to clear Multiple text fields ? please help

    Can you please write code ? i am beginner to java programming this might be tuff for me to do myself please help

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

    Default Re: how to clear Multiple text fields ? please help

    Quote Originally Posted by nadia.ahmed View Post
    Can you please write code ? i am beginner to java programming this might be tuff for me to do myself please help
    First, this is a forum, not a code factory. We will help you to write your own code, but we won't do it for you.

    Then, you will remain a beginner forever unless you make a start on learning how to solve your problems.

    Finally, writing code for you is not helpful.

    Have you looked at the class hierarchy for the Swing JComponents, as Jos suggested? What did you find there?

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

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

    Default Re: how to clear Multiple text fields ? please help

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

  6. #6
    nadia.ahmed is offline Member
    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Default Re: how to clear Multiple text fields ? please help

    yes i am studying class hierarchy for the Swing JComponents;

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,335
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to clear Multiple text fields ? please help

    Quote Originally Posted by nadia.ahmed View Post
    Can you please write code ? i am beginner to java programming this might be tuff for me to do myself please help
    You shouldn't be working on this problem as you do now, because you don't understand what you're doing; you probably scraped that bit of code from 'teh net' and expect miracles from it; that's not how programming works; clear those fields one by one.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. PDFBox multiple text lines and fields
    By igorland in forum New To Java
    Replies: 1
    Last Post: 02-02-2013, 01:21 PM
  2. Replies: 8
    Last Post: 08-13-2011, 06:02 PM
  3. Activating Text Fields
    By BennyJass in forum AWT / Swing
    Replies: 1
    Last Post: 01-15-2011, 11:13 PM
  4. Clear text from HTML ???
    By neostoreus in forum New To Java
    Replies: 2
    Last Post: 04-17-2009, 05:17 AM
  5. Help with text fields in Java
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:29 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
  •