0

首先我会告诉你它是怎么回事

picture_how_it_is

应该是这样的(请参阅下面我评论中的链接):

标签必须向上,并且 TabPane 必须在所有方向上用边距填充屏幕的其余部分。

这是使用 GridBagLayout 进行布局的代码:

// Layout --begin--
    this.mainPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    // Layout:headLineLabel --begin--
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.ipadx = 0;
    gbc.ipady = 0;
    gbc.insets = new Insets(0, 10, 0, 0);
    gbc.anchor = GridBagConstraints.FIRST_LINE_START;
    this.mainPanel.add(this.headLineLabel, gbc);
    // Layout:headLineLabel --end--

    // Layout:FestplattenreinigerGraphicalUserInterfaceTabbedPane --begin--
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.ipadx = 0;
    gbc.ipady = 0;
    gbc.insets = new Insets(10, 10, 10, 10);
    gbc.anchor = GridBagConstraints.CENTER;
    this.mainPanel.add(new FestplattenreinigerGraphicalUserInterfaceTabbedPane(), gbc);
    // Layout:FestplattenreinigerGraphicalUserInterfaceTabbedPane --end--
    // Layout --end--

你需要知道的事情:

  1. FestplattenreinigerGraphicalUserInterfaceTabbedPane 扩展了 JTabbedPane。
  2. 我尝试指定所有约束(即使使用它们的默认值)来练习。
  3. 如果我表扬主播,布局仍然是这样。

这件事有什么问题?

非常感谢!(对不起,我不能直接发布图片+只有 1 个链接,因为我是新人-.-)

4

3 回答 3

0

您已经遗漏了必要的 weightx 和 weighty ,否则所有内容都会在中间混为一谈。所以在添加 tabpane 之前添加:

gbc.weightx = 1.0;
gbc.weighty = 1.0;
于 2010-11-28T16:20:54.110 回答
0

要执行类似的操作,对于您的示例,我认为您可以使用 NetBeans 中的“自由设计”而不是 GridBagLayout,然后限制调整应用程序窗口大小的能力。

于 2010-11-28T16:22:16.360 回答
0

不要使用 GridBagLayout。试试边框布局。NORTH 中的标签和 CENTER 中的选项卡式窗格。

或者也许是一个垂直的 BoxLayout。

于 2010-11-28T16:34:38.917 回答