Shell 是一种框架或窗口的复合控件,它有一个作为父控件的 Display,这通常也是默认 设置。SWT 支持两种不同 Shell 类型:一是用于实现主窗口的顶级 Shell;二是用于实现对话 框的 Shell。
Shell()
Shell(Display display)
Shell(Display display, int style)
Shell(int style)
Shell(Shell parent)
Shell(Shellparent, int style)
Shell shell=new Shell()
Shell shell=-new Shell(display);
Shell shell=new Shell(display,SWT.ClOSE|SWT.MAX|SWT.MIN)
Shell shell=new Shell(SWT.ClOSE|SWT.MAX|SWT.MIN)
Shell shell=new Shell(new Shell())
Shell shell=new Shell(new Shell(),SWT.ClOSE|SWT.MAX|SWT.MIN)
Shell 提供了六种构造方法,其中 Shell(Shell parent)、Shell(Shell parent int style)传入的是 Shell 类的对象,创建一个对话框,其他几种构造方法传入的是 Display 类的对象,将会创建 一个顶级的 shell 窗口
package swt.dialog;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class ShellDialogExample {
public ShellDialogExample() {
final Display display = new Display();
// 将窗口设置成对话框
final Shell shell = new Shell(display, SWT.DIALOG_TRIM);
// 在 Shell 容器上采用网格式布局,
GridLayout grid = new GridLayout();
// 将容器设置成一列
grid.numColumns = 1;
shell.setLayout(grid);
shell.setText("Shell 对话框实例");
shell.setSize(270, 190);
Label label1 = new Label(shell, SWT.NONE);
label1.setImage(display.getSystemImage(SWT.ICON_ERROR));
// 设置提示性表情符
Label label2 = new Label(shell, SWT.NONE);
label2.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
Label label3 = new Label(shell, SWT.NONE);
label3.setImage(display.getSystemImage(SWT.ICON_WARNING));
Label label4 = new Label(shell, SWT.NONE);
label4.setImage(display.getSystemImage(SWT.ICON_QUESTION));
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
public static void main(String[] args) {
new ShellDialogExample();
}
}