I made a simple search gui method to search for products in DB and it works flawlessly. However, after the search is done I'd like to reset (JTextFields which are used to get parameters of search) to blank. Is there a method to do this without invoking another instance?
Asked
Active
Viewed 1.0k times
1
-
4`yourTextField.setText("");`? – assylias Mar 21 '12 at 14:21
-
@assylias now I feel silly. :) thanks – vedran Mar 21 '12 at 14:23
2 Answers
5
How about setting text content to empty strings,like this
myTextField.setText("");
And further more I think you might need a class which is inherited from JTextField and you can add all sorts of methods,Getters and setters in it (such as Clear() ) which may assists you and meets your needs..

DayTimeCoder
- 4,294
- 5
- 38
- 61
4
You want to give the class that holds the JTextFields a public void reset()
method, and in that method simply call setText("")
on all the JTextFields that need to be cleared. If you place all of the JTextFields in a collection such as a List<JTextField>
then you can easily close them all with a for loop:
public void reset() {
for(JTextField field : fieldList) {
field.setText("");
}
}

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373
-
You wouldn't happen to know how to do the same for JRadioButton? I tired .setSelected(false) but it didn't work – vedran Mar 21 '12 at 14:28
-
@vedran You should post a new question explaining the whole scenario,so it can get the attention – DayTimeCoder Mar 21 '12 at 14:34
-
2@vedran: you would call a method on the JRadioButton's ButtonGroup object, I think that it's `clearSelection()` but not sure. The ButtonGroup API will tell you. – Hovercraft Full Of Eels Mar 21 '12 at 14:35