簡體   English   中英

如何在另一個JPanel的中心添加一個JPanel?

[英]How to add a JPanel in the center of another JPanel?

我想像這樣在其中心的另一個JPanel WorldView頂部添加一個JPanel地圖

例

這是我的代碼:

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布局結合使用在組件周圍生成空白

有關更多詳細信息,請參見如何使用GridBagLayout如何使用邊框

將其添加到構造器中:setLayout(new FlowLayout(FlowLayout.CENTER));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM