到一组JTextField和JLabel

到一组JTextField和JLabel

本文介绍了setVisible(false)到一组JTextField和JLabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组JTextFieldJLabel.我希望它们最初不可见,所以我想使用对每个组件调用setVisible(false)的方法来初始化我的applet.

I have a group of JTextField and JLabel. I want them to initially not be visible so I thought to initialize my applet with a method which calls setVisible(false) for each of the components.

是否可以创建方法setVisible(false),该方法会将所有组件的可见性设置为false.最后,如果小程序中有40个组件,是否可以仅使用一个命令而不是40个命令来完成此操作?

Is it possible to create a method setVisible(false) which will set the visibility of all the components to false. Finally if I have 40 components in the applet, is it possible to do this with only one command instead of 40 commands?

推荐答案

将按钮和标签添加到JPanel中,然后只需使JPanel不可见即可通过一次调用将其全部隐藏.

Add your buttons and labels to a JPanel and then you can simply make your JPanel invisible to hide them all with one call.

jPanel.setVisible(false);

或者,将按钮和标签添加到JComponent列表,然后遍历它:

Alternatively, add your buttons and labels to a JComponent list, and then loop through it:

List<JComponent> list = new ArrayList<JComponent>();
list.add(button);
list.add(label);
for(JComponent c : list){
    c.setVisible(false);
}

这篇关于setVisible(false)到一组JTextField和JLabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:23