The standard layout managers that support component orientation are FlowLayout, BorderLayout, BoxLayout, GridBagLayout, and GridLayout. 建议看看The Java Tutorial
I always use the method as campfire11(营火) for example Container c = getContentPane(); c.setLayout(null); JButton btn1 = new JButton("btn1"); btn1.setBounds(new Rectangle(x, y, width, height)); //you can change x, y to change the position of btn1 in window, and change width, height to change the size of btn1 c.add(btn1);
无布局比较好搞,直接setLayout(null),然后用 setBounds()来放组件。
关于setBounds看下面:
void setBounds(int x,int y,int width,int height)
x,y是组件左上角的位置
width.height是组件的尺寸
for example
Container c = getContentPane();
c.setLayout(null);
JButton btn1 = new JButton("btn1");
btn1.setBounds(new Rectangle(x, y, width, height)); //you can change x, y to change the position of btn1 in window, and change width, height to change the size of btn1
c.add(btn1);
那么就算是我设置好了大小,当我引入这个管理器以后,管理器还是会调整这些button的位置的。