Java – empty all field swings at once
•
Java
I have a JPanel with many jtextfields and JCombo@R_779_2419 @Es and jradiobuttons, so I want them to be in the default value at one time
I've emptied each field one by one, but it takes a lot of time. Maybe I miss some fields, or sometimes I can add another field, so it's not practice at all
public void empty(){
field1.setText("");
field2.setText("");
field3.setText("");
...
}
Is there any way to make all fields empty at once?
thank you.
Solution
If jtextfields are not in the same container, this may be a method:
private List<JTextField> allTextFields = new ArrayList<JTextField>();
private JTextField createNewTextField(String text) {
JTextField textField = new JTextField(text);
allTextFields.add(textField);
return textField;
}
private void resetAllTextFields(){
for (JTextField textField : allTextFields) {
textField.setText("");
}
}
.. Then, instead of using the constructor jtextfield mytextfield = new jtextfield ("content"), use jtextfield mytextfield = createnewtextfield ("content");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
