我怎样才能在Java中创建这个GridLayout?

时间:2013-08-17 05:02:05

标签: java grid grid-layout boxlayout

我想制作一个特定的网格,但我不确定如何制作

-------------------------------------------
|                                         |
|                                         | <-- My Banner
|                                         |
-------------------------------------------
|                      |                  |
|      Panel1          |                  |
|                      |                  |
-----------------------|                  |
|                      |                  |
|      Panel2          |                  | <--Info or something. I want this space to be
|                      |                  |    a white area. Im going to put images here.
-----------------------|                  |
|                      |                  |
|      Panel3          |                  |
|                      |                  |
-------------------------------------------

所以我想知道我应该使用什么版面管理器?

1 个答案:

答案 0 :(得分:0)

这会给你你想要的结果:

    final JPanel mainPanel = new JPanel(new BorderLayout());
    final JPanel bottomLeftPanel = new JPanel(new GridLayout(3, 1));
    //add 3 panels to bottomLeftPanel
    final JPanel bottomRightPanel = new JPanel(new BorderLayout());
    final JPanel bottomPanel = new JPanel(new GridLayout(1, 2));
    bottomPanel.add(bottomLeftPanel);
    bottomPanel.add(bottomRightPanel);
    final JPanel topPanel = new JPanel(new BorderLayout());
    mainPanel.add(bottomPanel, BorderLayout.CENTER);
    mainPanel.add(topPanel, BorderLayout.NORTH);