⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stacklayouttest.java

📁 自己建立的项目
💻 JAVA
字号:
package com.swtSample.layout;

import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.SWT;

public class StackLayoutTest {
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		StackLayout layout = new StackLayout();
		shell.setLayout(layout);
		StackLayoutSelectionAdapter adapter = new StackLayoutSelectionAdapter(
				shell, layout);
		Button one = new Button(shell, SWT.PUSH);
		one.setText("one");
		one.addSelectionListener(adapter);
		Button two = new Button(shell, SWT.PUSH);
		two.setText("two");
		two.addSelectionListener(adapter);
		Button three = new Button(shell, SWT.PUSH);
		three.setText("three");
		three.addSelectionListener(adapter);
		layout.topControl = one;
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
}

class StackLayoutSelectionAdapter extends SelectionAdapter {
	Shell shell;

	StackLayout layout;

	public StackLayoutSelectionAdapter(Shell shell, StackLayout layout) {
		this.shell = shell;
		this.layout = layout;
	}

	public void widgetSelected(SelectionEvent event) {
		Control control = layout.topControl;
		Control[] children = shell.getChildren();
		int i = 0;
		for (int n = children.length; i < n; i++) {
			Control child = children[i];
			if (child == control) {
				break;
			}
		}
		++i;
		if (i >= children.length) {
			i = 0;
		}
		layout.topControl = children[i];
		shell.layout();
	}
}

⌨️ 快捷键说明

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