java 清除 JTextFields 的字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6582302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:28:30  来源:igfitidea点击:

Clearing JTextFields' field

javaswing

提问by siaooo

How do we clear a JTextField's field after inputing something in that field? Note: I made the JTextFields in my JOptionPane

在该字段中输入内容后,我们如何清除 JTextField 的字段?注意:我在 JOptionPane 中制作了 JTextFields

回答by RMT

Well to clear a JTextField, if you have a reference to it you can set the text to ""

清除 a JTextField,如果您有对它的引用,则可以将文本设置为 ""

field.setText("");

回答by Petar Minchev

To clear a specific JTextFieldcall field.setText(""). If you need something else please clarify your question.

清除特定JTextField呼叫field.setText("")。如果您需要其他东西,请澄清您的问题。

回答by Gagan

Just call setText("")instance method for the textfields.

只需setText("")为文本字段调用实例方法。