Pra*_*uja 3 java swing jframe jtextfield jtextarea
我正在使用NetBeans开发Java应用程序.我有5个JTextFields和2个JTextArea在JFrame.我想使用循环立即清除它们.怎么做到呢?
遍历所有的组件,并设置所有的文本JTextField和JTextArea对象为空字符串:
//Note: "this" should be the Container that directly contains your components
//(most likely a JPanel).
//This won't work if you call getComponents on the top-level frame.
for (Component C : this.getComponents())
{
if (C instanceof JTextField || C instanceof JTextArea){
((JTextComponent) C).setText(""); //abstract superclass
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9312 次 |
| 最近记录: |