Java 如何设置文本字段在框架中不可见
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3081713/
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
How to set the textfield is not visible in frame
提问by krishna
I am using Swing framework, and I have one question.
我正在使用 Swing 框架,我有一个问题。
The Address panel is dynamically added to the main frame. I want to call the visible(false)method from the main frame on the Address Panel.
地址面板会动态添加到主框架中。我想visible(false)从地址面板上的主框架调用该方法。
回答by jjnguy
What you need to do is store the JTextFieldas a private member of the AddressPanel. And, in AddressPanel, add a method called hideTextField(). Then, in that method call the setVisible(false)method on the private JTextFieldmember.
您需要做的是将 存储JTextField为AddressPanel. 并且,在 中AddressPanel,添加一个名为 的方法hideTextField()。然后,在该方法中调用setVisible(false)私有JTextField成员上的方法。
The code may look similar to the following:
该代码可能类似于以下内容:
public class AddressPanel {
private JTextField textFieldToHide;
public void hideTextField(){
textFieldToHide.setVisible(false);
}
}
Then, in the main frame use it like so:
然后,在主框架中像这样使用它:
addressPanel.hideTextField();

