【问题标题】:How can i make this GridLayout in Java?如何在 Java 中制作这个 GridLayout?
【发布时间】:2013-08-17 13:12:23
【问题描述】:

我有一个特定的网格我想制作,但我不知道如何制作它

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

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

【问题讨论】:

  • 要求代码的问题必须表明对所解决问题的最低理解。包括尝试的解决方案、为什么它们不起作用以及预期的结果。 (从标志箱复制)
  • 好吧,我试试看,稍后再贴出来
  • 这里有一个想法:使用BorderLayout 经理。将横幅放在北部区域,将图像空间放在东部区域,将面板 1-3 放入 JPanelBoxLayout 布局管理器到西部区域。
  • 嗯,是的,我认为这可行,我不经常使用它,我完全忘记了它。我试一试:)
  • @gparyani 这行不通,因为空白也会出现在横幅的东边,从他的图表来看,这不是他想要的。

标签: java grid grid-layout boxlayout


【解决方案1】:

这会给你想要的结果:

    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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 2016-06-17
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多