提交 26052565 编写于 作者: W weixin_47534470

Sun Feb 18 13:44:00 CST 2024 inscode

上级 7d7967f3
run = "javac Main.java && java Main"
language = "java"
[debugger]
program = "Main"
......@@ -3,24 +3,42 @@ import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;
public class SWTWindowExample {
private static final int SHELL_WIDTH = 400;
private static final int SHELL_HEIGHT = 300;
public static void main(String[] args) {
Display display = new Display();
Shell shell = createShell(display);
Composite composite = createComposite(shell);
createTable(composite);
createGroupWithRadioButtons(composite);
ScrolledComposite scrolledComposite = createScrolledComposite(shell, composite);
openShell(display, shell);
disposeDisplay(display);
}
private static Shell createShell(Display display) {
Shell shell = new Shell(display);
shell.setText("SWT Window Example");
shell.setSize(400, 300);
shell.setSize(SHELL_WIDTH, SHELL_HEIGHT);
return shell;
}
// 创建Composite容器
private static Composite createComposite(Shell shell) {
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new FillLayout(SWT.VERTICAL));
return composite;
}
// 创建左侧部分,显示BMIDE的lov值
private static void createTable(Composite composite) {
Table table = new Table(composite, SWT.BORDER | SWT.V_SCROLL);
for (int i = 0; i < 20; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText("Item " + i);
}
}
// 创建右侧部分,带单选按钮
private static void createGroupWithRadioButtons(Composite composite) {
Group group = new Group(composite, SWT.NONE);
group.setText("Options");
group.setLayout(new FillLayout(SWT.VERTICAL));
......@@ -28,19 +46,26 @@ public class SWTWindowExample {
button1.setText("Option 1");
Button button2 = new Button(group, SWT.RADIO);
button2.setText("Option 2");
}
// 设置滚动条
private static ScrolledComposite createScrolledComposite(Shell shell, Composite composite) {
ScrolledComposite scrolledComposite = new ScrolledComposite(shell, SWT.V_SCROLL);
scrolledComposite.setContent(composite);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setExpandHorizontal(true);
return scrolledComposite;
}
private static void openShell(Display display, Shell shell) {
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
private static void disposeDisplay(Display display) {
display.dispose();
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册