Java 和使用不同的实例

标签 java swing

我有一个程序,我可以在其中单击一个按钮,它会调用一个新面板,通过操作监听器使当前面板为 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/

相关文章:

java - 迭代 HTML 标签

java - Spring IO平台-bom版本方案

Java JFrame 放在前面

java - GUI 上的按钮有什么问题

java - 使用递归检查周围的单元格

java - 永久 SensorEventListener 震动

java - 如何在 Java 中组织图形和绘图

java - 刷新 JPanel-移动 JLabel

java - 仅当方法位于同一类中时才存储值

java - 在 Java 中按值对映射进行排序