gridbaglayoutstep2.java

来自「JAVA SE6 全方位学习 朱仲杰 编著 机械工业出版社出版」· Java 代码 · 共 39 行

JAVA
39
字号
import java.awt.*;public class GridBagLayoutStep2{	public static void main(String argv[])	{		Frame f = new Frame("GridBagLayout Step 2");		f.setLayout(new GridBagLayout());		int att[][] = { {0, 0, 1, 1, 1, 1}, 						{1, 0, 1, 1, 0, 0}, 						{2, 0, 1, 1, 1, 1},						{0, 1, 3, 1, 0, 0} };        Button b[] = new Button[4];		for (int i=0; i<b.length; i++)		{			b[i] = new Button("Button "+(i+1));			add(f, b[i], att[i]);		}		f.pack();		f.setVisible(true);	}	private static void add(Container con, Component com, int att[])	{		GridBagConstraints cons = new GridBagConstraints();		cons.gridx = att[0];		cons.gridy = att[1];		cons.gridwidth = att[2];		cons.gridheight = att[3];		cons.weightx = att[4];		cons.weighty = att[5];		con.add(com, cons);	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?