13

Possible Duplicate:
JButton needs to change JTextfield text

How do I clear a JTextField when a JButton is clicked?

Community
  • 1
  • 1
Monte
  • 131
  • 1
  • 1
  • 3
  • 1
    Look at answer to the question linked in the previous comment. You can clear the text by setting the text to an empty string. – Shawn Chin Mar 16 '11 at 17:14

1 Answers1

32

Looking for EventHandling, ActionListener?

or code?

JButton b = new JButton("Clear");
b.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
        textfield.setText("");
        //textfield.setText(null); //or use this
    }
});

Also See
How to Use Buttons

Alpine
  • 3,838
  • 1
  • 25
  • 18