SWT(JFace)体验之FillLayout布局
更新时间:2009年06月25日 11:11:07 作者:
FillLayout是非常简单的一种布局方式,它会以同样大小对父组件中的子组件进行布局,这些子组件将以一行或一列的形式排列。
FillLayout布局
FillLayout是非常简单的一种布局方式,它会以同样大小对父组件中的子组件进行布局,这些子组件将以一行或一列的形式排列。一般来说,用户可以在任务栏、工具栏中放置FillLayout布局,通过FillLayout布局对子组件进行定位,也可以当子组件只有一个组件时,通过FillLayout布局填充整个父组件的空间。
FillLayout的风格
FillLayout布局中,可以把子组件按水平或垂直的方式进行排列,这些风格是当创建FillLayout实类时以参数形式指定的。
演示代码:
package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FillLayoutSample {
Display display = new Display();
Shell shell = new Shell(display);
public FillLayoutSample() {
FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
fillLayout.marginHeight = 5;
fillLayout.marginWidth = 5;
fillLayout.spacing = 1;
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();
}
}
FillLayout是非常简单的一种布局方式,它会以同样大小对父组件中的子组件进行布局,这些子组件将以一行或一列的形式排列。一般来说,用户可以在任务栏、工具栏中放置FillLayout布局,通过FillLayout布局对子组件进行定位,也可以当子组件只有一个组件时,通过FillLayout布局填充整个父组件的空间。
FillLayout的风格
FillLayout布局中,可以把子组件按水平或垂直的方式进行排列,这些风格是当创建FillLayout实类时以参数形式指定的。
演示代码:
复制代码 代码如下:
package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FillLayoutSample {
Display display = new Display();
Shell shell = new Shell(display);
public FillLayoutSample() {
FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
fillLayout.marginHeight = 5;
fillLayout.marginWidth = 5;
fillLayout.spacing = 1;
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();
}
}
相关文章
解决spring-boot2.0.6中webflux无法获得请求IP的问题
这几天在用 spring-boot 2 的 webflux 重构一个工程,写到了一个需要获得客户端请求 IP 的地方,在写的过程中遇到很多问题,下面小编通过一段代码给大家介绍解决spring-boot2.0.6中webflux无法获得请求IP的问题,感兴趣的朋友跟随小编一起看看吧2018-10-10
SpringBoot 项目中的图片处理策略之本地存储与路径映射
在SpringBoot项目中,静态资源存放在static目录下,使得前端可以通过URL来访问这些资源,我们就需要将文件系统的文件路径与URL建立一个映射关系,把文件系统中的文件当成我们的静态资源即可,本文给大家介绍SpringBoot本地存储与路径映射的相关知识,感兴趣的朋友一起看看吧2023-12-12
java多线程之wait(),notify(),notifyAll()的详解分析
本篇文章是对java多线程 wait(),notify(),notifyAll()进行了详细的分析介绍,需要的朋友参考下2013-06-06


最新评论