JTabbedPane 连接到 JLayeredPane,其中有 2 个 JPanel?

发布于 2025-01-07 02:56:00 字数 1550 浏览 2 评论 0原文

我正在用 Java 编写一个应用程序,但我遇到了 JTabbedPane 的问题,其中 JTabbedPane 填充了包含 2 个 JPanel 的 JLayeredPane。我需要有两个不同的页面(配置文件和编辑配置文件),以便配置文件选项卡显示配置文件,并且配置文件 JPanel 中的“编辑配置文件”按钮将打开另一个带有编辑配置文件的 JPanel。首先这是一个可以接受的想法吗?

我有 Profile JPanel 和 editProfile JPanel 都使用 SpringLayout Manager。我读到 JLayeredPane 不能与 LayoutManager 一起使用,但通过在 JPanel 上使用它应该可以工作,对吗?我在下面写了一些示例代码,我觉得应该可以工作,但我得到的只是一个空白选项卡。任何帮助都会很棒。谢谢。

public class rework extends UserInterface {
private static SpringLayout infoLocation = new SpringLayout();
private static SpringLayout editLocation = new SpringLayout();
private static JPanel infoPane = new JPanel(infoLocation);
private static JPanel editPane = new JPanel(editLocation);
private static JLayeredPane manager = new JLayeredPane();
public static JLayeredPane displayScreen() {
    JLabel lblProfile = new JLabel("Profile");
    JLabel lblEditProfile = new JLabel("Edit Profile");

    infoPane.add(lblProfile, SpringLayout.WEST);
    editPane.add(lblEditProfile, SpringLayout.WEST);

    infoLocation.putConstraint(SpringLayout.WEST, lblProfile, 5, SpringLayout.WEST, infoPane);
    infoLocation.putConstraint(SpringLayout.NORTH, lblProfile, 5, SpringLayout.NORTH, infoPane);

    editLocation.putConstraint(SpringLayout.WEST, lblEditProfile, 5, SpringLayout.WEST, editPane);
    editLocation.putConstraint(SpringLayout.NORTH, lblEditProfile, 5, SpringLayout.NORTH, editPane);

    manager.add(editPane, JLayeredPane.DEFAULT_LAYER);
    manager.add(infoPane, JLayeredPane.PALETTE_LAYER);
    return manager;
}

}

I am writing an application in Java and I am running into issues with a JTabbedPane filled with a JLayeredPane that contains 2 JPanels. I need to have two different pages (profile and edit profile) so that the Profile Tab shows the profile and the button "edit profile" from the Profile JPanel will bring up another JPanel with Edit Profile. First off is this an acceptable idea?

I have the Profile JPanel and editProfile JPanel both using the SpringLayout Manager. I have read that the JLayeredPane won't work with LayoutManagers but by using it on JPanels it should work, right? I have some sample code that I've written below that i feel should work, but all i get is a blank tab. Any help would be great. Thanks.

public class rework extends UserInterface {
private static SpringLayout infoLocation = new SpringLayout();
private static SpringLayout editLocation = new SpringLayout();
private static JPanel infoPane = new JPanel(infoLocation);
private static JPanel editPane = new JPanel(editLocation);
private static JLayeredPane manager = new JLayeredPane();
public static JLayeredPane displayScreen() {
    JLabel lblProfile = new JLabel("Profile");
    JLabel lblEditProfile = new JLabel("Edit Profile");

    infoPane.add(lblProfile, SpringLayout.WEST);
    editPane.add(lblEditProfile, SpringLayout.WEST);

    infoLocation.putConstraint(SpringLayout.WEST, lblProfile, 5, SpringLayout.WEST, infoPane);
    infoLocation.putConstraint(SpringLayout.NORTH, lblProfile, 5, SpringLayout.NORTH, infoPane);

    editLocation.putConstraint(SpringLayout.WEST, lblEditProfile, 5, SpringLayout.WEST, editPane);
    editLocation.putConstraint(SpringLayout.NORTH, lblEditProfile, 5, SpringLayout.NORTH, editPane);

    manager.add(editPane, JLayeredPane.DEFAULT_LAYER);
    manager.add(infoPane, JLayeredPane.PALETTE_LAYER);
    return manager;
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文