Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the JTextField by clicking JButton [duplicate]

Possible Duplicate:
JButton needs to change JTextfield text

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

like image 692
Monte Avatar asked Mar 16 '11 17:03

Monte


1 Answers

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

like image 176
Alpine Avatar answered Oct 22 '22 05:10

Alpine