我有一个程序,我可以在其中单击一个按钮,它会调用一个新面板,通过操作监听器使当前面板为 false。该面板占用了 JFrame
的整个大小,为我提供了一个要填写的表单和要按下的按钮。
这是执行此操作的正确方法吗?或者,当我遇到新调用的 JPanel
出现在其他 JPanel
上的错误时,是否有更好的方法。我可以使用 setVisible(false)
但某些元素(例如按钮)不会出现。
最佳答案
根据你想要的,在我看来你可能想看看 CardLayout
您可以在其中切换框架中的 2 个或更多面板。
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
关于Java 和使用不同的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35870379/