2015-11-20 62 views
0

如何填充感興趣的網格單元格中可用的垂直和水平空間?GridBagConstraints同時填充垂直和水平線

例如:

JTextArea file1 = new JTextArea(); 
file1.setBorder(BorderFactory.createLineBorder(Color.black)); 
c = new GridBagConstraints(); 
c.gridx = 0; 
c.gridy = 1; 
c.weightx = 1.0/ELEMENTS_IN_WIDTH; 
c.weighty = 0.9; 
c.insets = new Insets(PAD, PAD, PAD, PAD); 
c.fill = GridBagConstraints.VERTICAL; 
mainPanel.add(file1, c); 

此垂直方向而不是水平地填充所述細胞。

VERTICAL值之後,很顯然,增加c.fill = GridBagConstraints.HORIZONTAL只會覆蓋的c.fill

OR「荷蘭國際集團他們像c.fill = GridBagConstraints.HORIZONTAL | GridBagConstraints.VERTICAL也不會做的伎倆值。

回答

3

你應該使用:

GridBagConstraints gridConst = new GridBagConstraints(); 
gridConst.fill = GridBagConstraints.BOTH; 
+0

呀謝謝...我已經找到它,因爲我在答覆中提到...(+1) –

1

我很匆忙,錯過了GridBagConstraints.BOTH這個明顯的領域。這個問題現在已經解決了......對於這個虛假的麻煩抱歉。