Results 1 to 7 of 7
- 07-20-2013, 11:14 AM #1
Member
- Join Date
- Jul 2013
- Posts
- 3
- Rep Power
- 0
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("") ;
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
resetTextFields(this);
}
- 07-20-2013, 11:19 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
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
JoBuild a wall around Donald Trump; I'll pay for it.
- 07-20-2013, 11:22 AM #3
Member
- Join Date
- Jul 2013
- Posts
- 3
- Rep Power
- 0
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
- 07-20-2013, 11:29 AM #4
Re: how to clear Multiple text fields ? 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?
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 07-20-2013, 11:33 AM #5
Re: how to clear Multiple text fields ? please help
If you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 07-20-2013, 11:39 AM #6
Member
- Join Date
- Jul 2013
- Posts
- 3
- Rep Power
- 0
Re: how to clear Multiple text fields ? please help
yes i am studying class hierarchy for the Swing JComponents;
- 07-20-2013, 11:53 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: how to clear Multiple text fields ? please help
Build a wall around Donald Trump; I'll pay for it.
Similar Threads
-
PDFBox multiple text lines and fields
By igorland in forum New To JavaReplies: 1Last Post: 02-02-2013, 02:21 PM -
Sorting Arraylist objects with multiple fields - Please help
By Chinnu55 in forum Advanced JavaReplies: 8Last Post: 08-13-2011, 07:02 PM -
Activating Text Fields
By BennyJass in forum AWT / SwingReplies: 1Last Post: 01-16-2011, 12:13 AM -
Clear text from HTML ???
By neostoreus in forum New To JavaReplies: 2Last Post: 04-17-2009, 06:17 AM -
Help with text fields in Java
By romina in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:29 AM
Bookmarks