Personally, I think that if you want to clean the content you should assign the initial values
public static void main(String s[]) {
JFrame frame = new JFrame("JFrame Example");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
JLabel etiqueta = new JLabel("Pon algo aqui");
final JTextField texto = new JTextField();
texto.setPreferredSize(new Dimension(100, 50));
JButton boton = new JButton();
boton.setText("Resetear datos");
boton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
texto.setText(null);
}
});
panel.add(etiqueta);
panel.add(texto);
panel.add(boton);
frame.add(panel);
frame.setSize(300, 100);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
In this example you only have one field but the operation will be the same:
Stuffed field
and when you press the button:
NOTES:
- the elements to be modified within the listener must be final
- if you have many elements, create a separate method