一列布局不使用窗口的全宽 [英] One column layout does not use full width of window

查看:115
本文介绍了一列布局不使用窗口的全宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个布局:2行,1列。第一排应占据窗户高度的70%,第二排应占窗户的30%。我通过使用 GridBagConstraints weighty 属性实现此目的。

I would like to create a layout: 2 rows, 1 column. 1st row should occupy 70% height of the window and 2nd row 30% of the window. I achieve this by using weighty attribute of GridBagConstraints.

但是我的组件宽度有问题,因为当我调整应用程序窗口的大小时,组件保持在中心,它的宽度是恒定的,我得到一个白色的空格组件的左侧和右侧(即使我将填充设置为 BOTH )。当我更改窗口的高度(组件调整得很好并填充窗口的完整高度)时不会发生此问题。

However I have problem with the width of my component, because when I resize application window the component remain in the center, its width is constant and I get a white spaces in the left and right of the component (even if I set fill to BOTH). This problem does not occur when I change the height of the window (components resize very well and fill full height of the window).

在我的约束下:

firstConstraints.gridx = 0;
firstConstraints.gridy = 0;  
firstConstraints.weighty = 0.7;
firstConstraints.fill = GridBagConstraints.BOTH;

secondConstraints.gridx = 0;
secondConstraints.gridy = 1;  
secondConstraints.weighty = 0.3;
secondConstraints.fill = GridBagConstraints.BOTH;


推荐答案

我认为你还需要:

gbc.weightx = 1.0;

请参阅如何使用GrigBagLayout 讨论权重x,重量约束。

See the secton from the Swing tutorial on How to Use a GrigBagLayout that talks about the weightx, weighty constraints.

这篇关于一列布局不使用窗口的全宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆