/**
* I'd like to achive following layout:
* +----------+----------+
* | Button 1 | |
* +----------| Button 2 |
* | Button 3 | |
* +----------+----------+
* with following code:
*/
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JButton button;
button = new JButton("Button 1");
c.weightx = 0.5;
c.weighty = 0.5;
c.fill = GridBagConstraints.BOTH;
panel.add(button, c);
button = new JButton("Button 2");
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridheight = 2;
panel.add(button, c);
button = new JButton("Button 3");
c.gridwidth = 1;
panel.add(button, c);
/**
* but what I achive is:
* +----------+----------+
* | Button 1 | Button 2 |
* +----------+----------+|
* | Button 3 |
* +----------+
*/
/**
* However layout:
* +----------+----------+
* | | Button 2 |
* + Button 1 +----------+
* | | Button 3 |
* +----------+----------+
* is easily achieved as:
*/
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JButton button;
button = new JButton("Button 1");
c.weightx = 0.5;
c.weighty = 0.5;
c.fill = GridBagConstraints.BOTH;
c.gridheight = 2;
panel.add(button, c);
button = new JButton("Button 2");
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridheight = 1;
panel.add(button, c);
button = new JButton("Button 3");
panel.add(button, c);
關於法國sc
不工作,結果與我的一樣,你試過了嗎? – francesc 2010-12-05 12:56:56