我想建立以下布局:
+--------------+-------+
| | |
| | O |
| GAME | P |
| | T |
| | |
+--------------+-------+
| |
| CONDITIONS |
| |
+--------------+-------+
而每个组件应该是一个框架
我决定使用
GridBagLayout
及其类似的功能:问题是很明显的:框架成为小型框架
以下是其中一个框架的示例代码(它们几乎都是相同的):如您所见,它们还没有执行任何操作
public class Game extends JInternalFrame {
public Game(){
super("Game");
}
}
这是我建立布局的方式:
//set dimension (x, y)
this.setSize(900, 600);
//deny resizing
this.setResizable(false);
//set position (x: top, y: left)
this.setLocation(300, 300);
[....]
this.options = new Options();
this.conditions = new Conditions();
this.game = new Game();
this.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.VERTICAL;
c.gridx = 1;
c.gridy = 0;
this.add(this.options, c);
c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
c.gridy = 0;
this.add(this.game, c);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 2;
this.add(this.conditions, c);
this.options.setVisible(true);
this.conditions.setVisible(true);
this.game.setVisible(true);
所以我的问题是
1)我如何获得框架以充分利用窗户的空间
2)如何使它们的大小不同(由于
this.options.setSize(...)
不起作用?)PS:这是完整的代码:http://pastebin.com/TSWyyi7v
最佳答案
根据您的图片,BorderLayout会更容易:
setLayout( new BorderLayout() );
add(game, BorderLayout.CENTER);
add(options, BorderLayout.EAST);
add(conditions, BorderLayout.SOUTH);