📄 form.jvt
字号:
import
org.eclipse.swt.SWT
org.eclipse.swt.layout.FormAttachment
org.eclipse.swt.layout.FormData
org.eclipse.swt.layout.FormLayout
org.eclipse.swt.widgets.Button
org.eclipse.swt.widgets.Display
org.eclipse.swt.widgets.Shell
method
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell();
shell.setSize(400, 300);
shell.setLayout(new FormLayout());
shell.setText("FormLayout test");
{
final Button upperLeft = new Button(shell, SWT.NONE);
final FormData formData = new FormData();
formData.top = new FormAttachment(0, 5);
formData.left = new FormAttachment(0, 5);
upperLeft.setLayoutData(formData);
upperLeft.setText("Upper Left Corner");
}
{
final Button upperRight = new Button(shell, SWT.NONE);
final FormData formData = new FormData();
formData.right = new FormAttachment(100, -5);
formData.top = new FormAttachment(0, 5);
upperRight.setLayoutData(formData);
upperRight.setText("Upper Right Corner");
}
{
final Button lowerLeft = new Button(shell, SWT.NONE);
final FormData formData = new FormData();
formData.bottom = new FormAttachment(100, -5);
formData.left = new FormAttachment(0, 5);
lowerLeft.setLayoutData(formData);
lowerLeft.setText("Lower Left Corner");
}
{
final Button lowerRight = new Button(shell, SWT.NONE);
final FormData formData = new FormData();
formData.bottom = new FormAttachment(100, -5);
formData.right = new FormAttachment(100, -5);
lowerRight.setLayoutData(formData);
lowerRight.setText("Lower Right Corner");
}
Button centered;
{
centered = new Button(shell, SWT.NONE);
final FormData formData = new FormData();
formData.bottom = new FormAttachment(50, 25);
formData.right = new FormAttachment(50, 50);
formData.top = new FormAttachment(50, -25);
formData.left = new FormAttachment(50, -50);
centered.setLayoutData(formData);
centered.setText("Centered");
}
{
final Button attached = new Button(shell, SWT.NONE);
final FormData formData = new FormData();
formData.top = new FormAttachment(centered, 5, SWT.BOTTOM);
formData.left = new FormAttachment(centered, 5, SWT.RIGHT);
attached.setLayoutData(formData);
attached.setText("Attached");
}
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -