Java开发GUI之GridBagLayout布局
GridBagLayout布局管理器是比GridLayout布局更加强大的表格布局。GridLayout进行的表格布局其中元素尺寸相同,而GridBagLayout则可以灵活配置其中元素的尺寸和位置。同样,GridBagLayout的使用也更加复杂,其布局依赖GridBagConstraints类。
先看如下经典示例:
static void GridBagLayoutTest(){
Frame frame = new Frame("GridBag");
GridBagLayout layout = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
Panel pannel = new Panel(layout);
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
Button button1 = new Button("Button1");
layout.setConstraints(button1, constraints);
pannel.add(button1);
Button button2 = new Button("Button2");
layout.setConstraints(button2, constraints);
pannel.add(button2);
Button button3 = new Button("Button3");</