如何设置文本字段在框架中不可见 [英] How to set the textfield is not visible in frame

查看:41
本文介绍了如何设置文本字段在框架中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Swing 框架,我有一个问题.

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

地址面板是动态添加到主框架的.我想从地址面板上的主框架调用 visible(false) 方法.

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.

推荐答案

您需要做的是将 JTextField 存储为 AddressPanel 的私有成员.并且,在AddressPanel 中,添加一个名为hideTextField() 的方法.然后,在该方法中调用私有 JTextField 成员上的 setVisible(false) 方法.

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

这篇关于如何设置文本字段在框架中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆