java - 一次将 CardLayout 中的多张卡片设置为 False

标签 java swing visible cardlayout

我理解的概念是,使用 Swing 的卡片布局,要切换卡片,您可以简单地调用您想要的卡片并将可见性设置为 true 或 false。例如,给定四张名为 a、b、c 和 d 的卡片,我希望显示 a,但不显示 b、c 和 d。现在,我的代码集与此类似:

a.setVisible(true);
b.setVisible(false);
c.setVisible(false);
d.setVisible(false);

无论如何,我不必调用所有四张卡并单独设置它们的可见性,而是可以一次调用所有卡,将它们设置为 false,然后将卡 a 设置为 true? 例如

//some method to set all cards to false
a.setVisible(true);

如有任何帮助,我们将不胜感激!

最佳答案

I understand the concept that with Card Layout for Swing, to switch cards, you can simply call the card you want and set the visibility to either true or false

不,这不是这个概念。您永远不会玩弄面板的可见性。 CardLayout 会为您做到这一点。您所要做的就是使用 show()、next() 或 previous() 方法。

阅读 Swing 教程中关于 How to Use Card Layout 的部分一个工作示例。

关于java - 一次将 CardLayout 中的多张卡片设置为 False,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20292935/

相关文章:

java - 更改 servlet 映射会引发 "HTTP Status 405 - Request method ' GET' 不支持”

java - 使用Java连接到外部mysql数据库

java - 程序运行时JButton中的图标不显示,可能是什么原因?

.net - 如何使用 Windbg 判断 .Net 控件是否可见

python - Selenium - 元素不可见 [Python]

javascript - 仅当第二个 div 在 View 中时才在滚动时保持 div 可见

Java PriorityQueue Comparator 在特定条件下插入二维数组

java - 通过匿名类

java - JTextField.selectAll() 的工作方式很奇怪

Java:在子 jDialog 中更新数据后刷新我的 jTable