📄 gridlayoutsample.java
字号:
package rcpbook.swtjface.sample;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class GridlayoutSample {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(240, 180);
shell.setText("GridLayout布局");
GridLayout layout = new GridLayout();
layout.numColumns = 3;
layout.marginTop = 10;
layout.marginBottom = 10;
layout.marginRight = 10;
layout.horizontalSpacing = 10;
layout.makeColumnsEqualWidth = true;
shell.setLayout(layout);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.widthHint = 60;
gridData.heightHint = 100;
gridData.verticalSpan = 2;
Button button1 = new Button(shell, SWT.NONE);
button1.setText("按钮1");
button1.setLayoutData(gridData);
gridData = new GridData(GridData.FILL_BOTH);
Button button2 = new Button(shell, SWT.NONE);
button2.setText("按钮2");
button2.setLayoutData(gridData);
gridData = new GridData(GridData.FILL_BOTH);
Button button3 = new Button(shell, SWT.NONE);
button3.setText("按钮3");
button3.setLayoutData(gridData);
gridData = new GridData(GridData.FILL_BOTH);
Button button4 = new Button(shell, SWT.NONE);
button4.setText("按钮4");
button4.setLayoutData(gridData);
Button button5 = new Button(shell, SWT.NONE);
button5.setText("按钮5");
button5.setLayoutData(gridData);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -