GridBagLayout不占用所有可用空间

时间:2016-01-05 06:19:55

标签: java swing layout-manager gridbaglayout

初始化面板并将其设置为GridBagLayout时,两个封装的面板不会展开以填充所有可用区域。像这样:

As you can see it is a lot smaller compared to the available space

代码:

    containerPanel.setLayout(new GridBagLayout());

    add(containerPanel);

    contentPanel = new JPanel();

    constraints.fill = GridBagConstraints.VERTICAL;

    constraints.gridx = 0;
    constraints.gridy = 0;

    containerPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));

    containerPanel.add(contentPanel, constraints);

    sidebarPanel = new JPanel();

    constraints.fill = GridBagConstraints.VERTICAL;

    constraints.gridx = 1;
    constraints.gridy = 0;

    constraints.weightx = 0.33;
    constraints.weighty = 2;

    sidebarPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));

    containerPanel.add(sidebarPanel, constraints);

0 个答案:

没有答案