Reputation: 21
I'm trying to set about 144 jPanels all setVisible(false) and I'd like to do it all at once rather than jPanel1.setVisible(false); 144 times. Is there an easier way to do this? I've tried to put the panels in an array but I'm using GUI swing on netbeans and the jPanels are already declared when I put them into the jFrame and when I try putting them in an array and using a for loop I get a null pointer error.
It's probably easy but I've looked all over the web and can't even find a topic on it.
Once again trying to set multiple (144 to be exact) jPanels in a jFrame to visible false at one time.
Upvotes: 2
Views: 868
Reputation: 6908
Why don't you set a JPanel parent for those JPanels and hide it?
Upvotes: 5
Reputation: 654
You can start with the root pane or common parent and walk down the hierarchy looking for panels with a common property value. Almost every swing app I work on ends up with a find(Container, Predicate) helper function somewhere.
Upvotes: 1