📄 helloworld.java
字号:
package com.swtdesigner;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class HelloWorld {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(236, 164);
shell.setText("SWT Application");
//定义一个文本框,样式风格为带边框
final Text text = new Text(shell, SWT.BORDER);
/**
* 对文本框进行在窗体上定位,通用模式为:
* setBounds(int x,int y,int width,int hight)
* x表示横坐标;y表示纵坐标;width表示文本框长度;
* hight表示文本框的高度
*/
text.setBounds(36, 37, 84, 21);
//定义一个按钮
final Button button = new Button(shell, SWT.NONE);
button.setText("button");
button.setBounds(134, 38, 57, 20);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -