I have a JButton and when I push it, it has to clear all the content in a JTextfield. How can I do this? Maybe there exists a method to clear a JTextfield or do I have to set the field to null
?
The JTextField#setText
method should do it with an empty String
as text.
As for reacting on the JButton
click, attach an ActionListener
to it. The Swing tutorials illustrate this all in great detail.