Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Nadia Ahmed
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i do not want to clear one by one it will takes so much time
jtext1.setText("");

one by one
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nadia Ahmed, welcome to the Ranch! Please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/80227-how-clear-multiple-text-fields-please-help.html
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3395
13
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nadia Ahmed
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i am using netbeans and i am just drag textfields into the different panel i made in the form
 
Rob Camick
Ranch Hand
Posts: 2559
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic