How to clear the JTextField by clicking JButton

Monte picture Monte · Mar 16, 2011 · Viewed 172.6k times · Source

Possible Duplicate:
JButton needs to change JTextfield text

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

Answer

Alpine picture Alpine · Mar 16, 2011

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