shellmodality.java

来自「eclipse开发笔记」· Java 代码 · 共 39 行

JAVA
39
字号
package book.ch5;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ShellModality {
	public static void main(String[] args) {
		Display display = Display.getDefault();
		Shell shell1 = new Shell(display);
		shell1.setText("Shell 1");
		shell1.setSize(206, 149);

		Shell shell2 = new Shell(display);
		shell2.setSize(206, 150);
		shell2.setText("Shell 2");

		shell1.open();
		shell2.open();

		Shell primaryShell = new Shell(shell1, SWT.DIALOG_TRIM
				| SWT.PRIMARY_MODAL);
		primaryShell.setText("This window will block shell 1 only");
		primaryShell.setSize(300, 80);
		primaryShell.open();

		Shell applicationShell = new Shell(shell1, SWT.DIALOG_TRIM
				| SWT.APPLICATION_MODAL);
		applicationShell.setText("This window will block both");
		applicationShell.setSize(300, 80);
		applicationShell.open();

		while (!(shell1.isDisposed() && shell2.isDisposed()))
			if (!display.readAndDispatch())
				display.sleep();
		display.dispose();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?