我可以在 Java 中的 CardLayout 中添加多个框架吗?

Can I add multiple frames in CardLayout in Java?

我的程序中有五个 JFrame。我希望它们在 CardLayout 中。 假设A为主框架,B,C,D,E为子框架。 现在,我想在 A 中放置四个按钮,它们将分别打开子框架。所有子框架都会有一个 'Back' 按钮返回主框架。我如何在 CardLayout 中执行此操作? 让我知道是否有任何其他布局可以这样做。

不,JFrametop-level container. Presumably, each of your existing frames sets or adds a container to the content pane, so you can add those containers to the CardLayout. Several examples are shown here. Also consider a JToolBar, seen here,用于您的导航面板。