GridLayout是以行作为优先考虑的因素的:
When both the number of rows and the number of columns have been set to non-zero values, either by a constructor or by the setRows and setColumns methods, the number of columns specified is ignored. Instead, the number of columns is determined from the specified number or rows and the total number of components in the layout. So, for example, if three rows and two columns have been specified and nine components are added to the layout, then they will be displayed as three rows of three columns. Specifying the number of columns affects the layout only when the number of rows is set to zero.
你把行数设为0就可以了。
Specifying the number of columns affects the layout only when the number of rows is set to zero.
When both the number of rows and the number of columns have been set to non-zero values, either by a constructor or by the setRows and setColumns methods, the number of columns specified is ignored. Instead, the number of columns is determined from the specified number or rows and the total number of components in the layout. So, for example, if three rows and two columns have been specified and nine components are added to the layout, then they will be displayed as three rows of three columns. Specifying the number of columns affects the layout only when the number of rows is set to zero.
你把行数设为0就可以了。
Specifying the number of columns affects the layout only when the number of rows is set to zero.
解决方案 »
- 如何将button group的两个align属性集成在一起?
- java和Tomcat环境变量的问题?
- 我想把以下代码的查询结果和过程存到一个文本里
- 类的定义
- java各种处理时间的方法
- 我是JSP初学者,请教牛人一个问题
- 求助:ICMP在Java下的实现
- 请问:为什么我写的applet 程序用appletviewer 可以运行,但用IE就是不行,java控制台有提示...
- 请高手指点迷津
- 我用JBuilder6制作Applet小程序,然后用Archive Builder捆绑Applet所需的文件,如果我用AWT中的控件,Applet.html执行后可以启动Applet,
- ORA-01000: 超出打开游标的最大数!!!怎么办?高分!!!
- 我想学JAVA,各位高手给些建议。
setLayout(null);//p1的父容器設為絕對座標
Panel p1 = new Panel(new FlowLayout());//還要設置好panel的大小
p1.setSize(300,200);
p1.setLocation(0,0);
p1.add(new Label("物料代碼"));
p1.add(new Label("物料名稱"));
add(p1);你要比較熟悉几種常用的佈局管理器:
FlowLayout:流式佈局,從左至右,當一行擺滿後換一行繼續從左向右擺放
GridLayout:網格佈局,將容器分成尺寸相同的網格,順序與FlowLayout一樣
BorderLayout:邊緣佈局,可擺放"North","South","East","West","Center"
CardLayout:將每個部件放在單獨的卡上,在某一時刻只有一個部件可見
GridBagLayout:也是單元網格,但部件可以佔用多個單元
null:空布局,可以在一定的座標上顯式的放置部件,需要setLocation,setSize