gpt4 book ai didi

java - JPanel 位于另一个 JPanel 之上

转载 作者:行者123 更新时间:2023-12-01 18:00:56 24 4
gpt4 key购买 nike

我已经使用 JPanel 一段时间了,现在想将一个 JPanel 放在另一个 JPanel 之上。

我已经考虑过使用 JLayer 但我想知道是否有一个解决方案只设置底部和顶部的层,如果可能的话我不想设置每个组件层。

示例

JPanel bottomPanel = new JPanel();      # Set as bottom panel
JPanel topPanel = new JPanel(); # Set as top panel
JPanel sidePanel = new JPanel(); # Don't have to set
JPanel anotherSidePanel = new JPanel(); # Don't have to set

如果这不可能,最好的解决方案是什么,谢谢。

最佳答案

您可以让主面板使用BorderLayout

然后你可以这样做:

mainPanel.add(leftSide, BorderLayout.LINE_START);
mainPanel.add(rightSide, BorderLayout.LINE_END);
JLayeredPane lp = new JLayeredPane();
mainPanel.add(lp, BorderLayout.CENTER);

关于java - JPanel 位于另一个 JPanel 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40954329/

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