formlayoutsample.java
来自「个人珍藏」· Java 代码 · 共 48 行
JAVA
48 行
package rcpbook.swtjface.sample;
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 FormLayoutSample {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(240, 200);
shell.setText("FormLayout布局");
FormLayout layout = new FormLayout();
layout.marginTop = 5;
layout.marginLeft = 5;
layout.marginRight = 5;
shell.setLayout(layout);
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("按钮1");
FormData formData = new FormData();
formData.height = 40;
formData.right = new FormAttachment(100, -100);
formData.left = new FormAttachment(0, 10);
formData.top = new FormAttachment(1, 10, 0);
button1.setLayoutData(formData);
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("按钮2");
formData = new FormData();
formData.height = 60;
formData.width = 90;
button2.setLayoutData(formData);
formData.top = new FormAttachment(button1, 5, SWT.BOTTOM);
formData.left = new FormAttachment(button1, -10, SWT.RIGHT);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?