gpt4 book ai didi

java - 如何在另一个 JPanel 的中心添加一个 JPanel?

转载 作者:行者123 更新时间:2023-12-01 10:01:35 25 4
gpt4 key购买 nike

我想在其中心的另一个 JPanel WorldView 之上添加一个 JPanel map ,就像这样

Example

这是我的代码:

public class WorldView extends JPanel implements ActionListener{

private JPanel map;

public WorldView() throws IOException{
this.setSize(1024,768);
this.setBackground(Color.BLACK);
map = new JPanel();
this.add(map);
}

最佳答案

您可以使用 GridBagLayout 并修改 GridBagConstraints#insetsEmptyBorder 结合生成组件周围的空白>GridBagLayout 或其他一些布局,例如 BorderLayout

参见How to Use GridBagLayoutHow to Use Borders了解更多详情

关于java - 如何在另一个 JPanel 的中心添加一个 JPanel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36780863/

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