gpt4 book ai didi

java - 卡片布局 : How can I tell which card is visible?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:16:27 24 4
gpt4 key购买 nike

我一直在查看 Swing 的文档 CardLayout而且似乎没有任何方法可以确定当前正在向类(class)展示哪张卡片。但是必须有一种方法可以询问布局当前显示的是哪张卡片,对吧?

由于项目限制,我不能简单地扩展它并将此功能添加到子类中,所以如果没有这样的功能是否意味着我无法跟踪组件外部的组件状态(哎呀!),或者在 Swing 的深处是否还有其他选择?

最佳答案

根据 How to Use CardLayout教程,

Conceptually, each component that a CardLayout manages is like a playing card or trading card in a stack, where only the top card is visible at any time. You can choose the card that is showing in any of the following ways:

  • By asking for either the first or last card, in the order it was added to the container
  • By flipping through the deck backwards or forwards
  • By specifying a card with a specific name

尝试,

Component visibleComponent = foo.getComponent(0);

哪里fooJPanel使用 CardLayout 的实例.

引用:

关于java - 卡片布局 : How can I tell which card is visible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7078800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com