📄 formattachment1.java
字号:
package cn.com.chengang.swt;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FormAttachment1 {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
// ---------创建窗口中的其他界面组件-------------
shell.setLayout(new FormLayout());
Button button = new Button(shell, SWT.NONE);
button.setText("button");
FormData formData = new FormData();
// 按钮的顶端(formData.top)离shell容器的空白边距是shell容器总体空白长度的60%
formData.top = new FormAttachment(60, 0);
button.setLayoutData(formData);
// -----------------END------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -