开发者

setVisible(false) to a group of JTextField and JLabel

I have a group of JTextField and JLabel. I开发者_C百科 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.

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?


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

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜