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
  • 20,587
  • 21
  • 94
  • 129
Fseee
  • 2,458
  • 9
  • 39
  • 57

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
  • 254,755
  • 72
  • 386
  • 405
  • 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