简体   繁体   中英

Setting multiple jPanels to invisible at the same time

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.

为什么不为这些JPanel设置一个JPanel父级并将其隐藏?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM