同时将多个 jPanel 设置为不可见
我正在尝试将大约 144 个 jPanel 设置为全部 setVisible(false),并且我想一次性完成所有操作,而不是 jPanel1.setVisible(false); 144次。有没有更简单的方法来做到这一点? 我尝试将面板放入数组中,但我在 netbeans 上使用 GUI swing,并且当我将它们放入 jFrame 中时,jPanel 已经被声明,当我尝试将它们放入数组中并使用 for 循环时,我得到一个空指针错误。
这可能很容易,但我查遍了整个网络,甚至找不到有关它的主题。
再次尝试一次将 jFrame 中的多个(确切地说是 144 个)jPanel 设置为可见 false。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不为这些 JPanel 设置一个 JPanel 父级并隐藏它?
Why don't you set a JPanel parent for those JPanels and hide it?
您可以从根窗格或公共父窗格开始,然后沿着层次结构查找具有公共属性值的面板。几乎我开发的每个 swing 应用程序最终都会在某个地方有一个 find(Container, Predicate) 辅助函数。
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.