FillLayout布局实例
FillLayout是简单而且很常用的布局,下面通过实例展示FillLayout的布局效果,代码如例程1所示。
例程1 FillLayoutSample.java
| ** * 为了节省篇幅,所有的import类已经被注释 * 读者可以通过ctrl+shift+o快捷键,自动引入所依赖的类 * 如果有问题可发邮件到ganshm@gmail.com * */ public class FillLayoutSample { Display display = new Display(); Shell shell = new Shell(display); public FillLayoutSample() { //新建FillLayout布局,设置子组件与水平方式排列 FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL); //指定子组件的上、下边距为多少像素 fillLayout.marginHeight = 25; //指定子组件的左、右边距为多少像素 fillLayout.marginWidth = 25; //指定子组件之间距离为多少像素 fillLayout.spacing = 10; //设定父组件的布局方式 shell.setLayout(fillLayout); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button number 2"); Button button3 = new Button(shell, SWT.PUSH); button3.setText("3"); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } public static void main(String[] args) { new FillLayoutSample(); } } |
程序中通过marginHeight、marginWidth和spacing指定了边距和子组件的间距,程序运行效果如图1所示。

图1 FillLayout布局实例
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- Eclipse应用技术 (514篇文章)
- ASP.NET教程 (8457篇文章)
- Wlan组网----家庭专题 (4206篇文章)
- FreeBSD使用教程 (6580篇文章)
- Eclipse 开发技术 (132篇文章)
- J2SE综合:浅谈java程序发布之 jre 篇 (11次浏览)
- JAVA代码中使用魔法数值 (8次浏览)
- Hibernate缓存管理 (6次浏览)
- JAVA代码应该流畅和结构化 (5次浏览)
- Java JVM设置对性能的影响 (4次浏览)
- 开发框架:深入了解 Struts Validator (3次浏览)
- Java中的通信机制及与C/C API的集成 (1次浏览)
- 用Hibernate实现领域对象的自定义字段 (1次浏览)
- Java语言入门 简述Java语言回收机制 (0次浏览)
- 2008年Java开发者最迫切的五个期望 (0次浏览)



