【问题标题】:How to clear the JTextField by clicking JButton [duplicate]如何通过单击 JButton 清除 JTextField [重复]
【发布时间】:2011-07-16 18:47:07
【问题描述】:

可能重复:
JButton needs to change JTextfield text

点击JButton 时如何清除JTextField?

【问题讨论】:

  • 查看上一条评论中链接的问题的答案。您可以通过将文本设置为空字符串来清除文本。

标签: java swing reset jbutton jtextfield


【解决方案1】:

正在寻找EventHandling、ActionListener?

还是代码?

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

另见
How to Use Buttons

【讨论】:

    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多