permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes How to reset all the JtextFields from multiple panel in one form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to reset all the JtextFields from multiple panel in one form" Watch "How to reset all the JtextFields from multiple panel in one form" New topic
Author

How to reset all the JtextFields from multiple panel in one form

Nadia Ahmed
Greenhorn

Joined: Jul 20, 2013
Posts: 7
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 JtectFields
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



button i am calling is


please help me
Nadia Ahmed
Greenhorn

Joined: Jul 20, 2013
Posts: 7
i do not want to clear one by one it will takes so much time
jtext1.setText("");

one by one
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Nadia Ahmed, welcome to the Ranch! Please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/80227-how-clear-multiple-text-fields-please-help.html


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Your meaningless variable names imply that you are using the NetBeans visual designer. That isn't a beginners' tool; you should write your own GUI code, using meaningful variable names, until you are familiar with Swing coding.

i do not want to clear one by one it will takes so much time

No, it won't. Don't guess at bottlenecks; write clear maintainable code, test it, and if there is a performance issue (there won't be), profile the code to wee wheree it needs to be optimized.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2229
    
    7

How are you creating the JTextFields? Do these text fields have the same action listener (pointing to the reset action)?

In your sample code, are you trying to use the JPanel's array? Why checking if the component is a "container" when you just want a JTextField? The resetTextField method can pass in the entire array and do the checking and looping inside.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Nadia Ahmed
Greenhorn

Joined: Jul 20, 2013
Posts: 7
Well i am using netbeans and i am just drag textfields into the different panel i made in the form
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
The code you posted looks reasonable. Make sure you pass in the proper parameter to the resetTextFields() method. You currently use "this" but I have no idea what "this" refers" to. I would guess you want to pass in the content pane of the frame. So you could change your code to something like:

 
wood burning stoves
 
subject: How to reset all the JtextFields from multiple panel in one form
 
Similar Threads
Problem in Reset button.
About design pattern used in SCJD
Error message
What's up with a random number like this being displayed 889193265?
problem with JTextField null