我想創建一個佈局:2行,1列。第一排佔窗戶高度的70%,第二排佔窗戶的30%。我通過使用GridBagConstraints
的weighty
屬性來實現此目的。一列布局不使用窗口的全角
但是,我的組件的寬度有問題,因爲當我調整應用程序窗口大小時,組件的寬度保持不變,並且在組件的左側和右側得到一個空白區域(即使我設置爲fill
至BOTH
)。當我改變窗口的高度時,不會發生這個問題(組件調整得非常好,並填充窗口的整個高度)。
下面我約束:
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;
您是否嘗試過建立和錨約束? – 2012-01-05 16:42:34