SWT Shell容器支持的5种事件

Shell容器支持的五种事件分别是:Activate , Close , Deactivate , Deiconfiy , Uconify;


  1. Activate:窗户活动时候触发。创建窗口,或者焦点落入窗口都触发该事件;
  2. Close:Shell关闭时,触发;
  3. Deactivate:Shell从活动变为非活动时触发;
  4. Deiconfiy:Shell从最小化恢复初始状态时触发;
  5. Uconify:Shell最小化时触发;

代码示例:


public static void main(String args[]) {

		Display display = Display.getDefault();
		Shell shell = new Shell(display, SWT.SHELL_TRIM);

		shell.setText("SWT Window");
		shell.setSize(400, 200);
		final Text text = new Text(shell, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
		text.setBounds(10, 10, 380, 150);
		shell.addShellListener(new ShellListener() {
			public void shellActivated(ShellEvent e) {
				text.append("Shell has been activated\n");
			}

			public void shellClosed(ShellEvent e) {
				System.out.println("Shell has been closed");
			}

			public void shellDeactivated(ShellEvent e) {
				text.append("Shell has been deactivated\n");
			}

			public void shellDeiconified(ShellEvent e) {
				text.append("Shell has been deiconified\n");
			}

			public void shellIconified(ShellEvent e) {
				text.append("Shell has been iconified\n");
			}
		});

		shell.open();

		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}

	}


你可能感兴趣的:(J2SE,读书笔记)