How to set the textfield is not visible in frame

China☆狼群 提交于 2019-12-10 18:32:54

问题


I am using Swing framework, and I have one question.

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.


回答1:


What you need to do is store the JTextField as 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 JTextField member.

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();


来源:https://stackoverflow.com/questions/3081713/how-to-set-the-textfield-is-not-visible-in-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!