1

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.

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?

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
Fseee
  • 2,476
  • 9
  • 40
  • 63

1 Answers1

3

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);
}
dogbane
  • 266,786
  • 75
  • 396
  • 414
  • I'm building a japplet so each jbutton, jlabels etc.. declaration is not editable... any ideas? Anyway it's an excellent suggestion, thank you – Fseee Mar 02 '11 at 13:28