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

📄 stacklayoutexample.java

📁 Eclipse SWT/JFace开发实战精解, 随书源代码。
💻 JAVA
字号:
/**
 *@author: WangJinTao,MengQingChang2006
 */
package layoutManager;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;

public class StackLayoutExample {

	public StackLayoutExample() {
		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setSize(500, 375);
		shell.setText("StackLayout实例");
		// 在shell应用网格式布局,把shell容器设置为2列
		shell.setLayout(new GridLayout(2, false));
		// 定义了Stacklayout对象
		final StackLayout stacklayout = new StackLayout();
		// 定义了面板容器
		final Composite composite = new Composite(shell, SWT.BORDER);
		// 使用GriData控制布局,使面板双向充满容器
		GridData gridData = new GridData(GridData.FILL_BOTH);
		// 使composite1水平抢占2列
		gridData.horizontalSpan = 2;
		composite.setLayoutData(gridData);
		// 在composite1上应用stacklayout
		composite.setLayout(stacklayout);

		final Text text = new Text(composite, SWT.NONE);
		text.setText("文本 ");

		final Button button = new Button(composite, SWT.NONE);
		button.setText("按钮");

		final Button button1 = new Button(shell, SWT.NONE);
		button1.setText("单击显示文本");
		button1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				// 用topControl使文本框(text)显示在堆栈的顶端
				stacklayout.topControl = text;
				composite.layout();
			}
		});
		final Button button2 = new Button(shell, SWT.NONE);
		button2.setText("单击显示按钮");
		button2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				stacklayout.topControl = button;
				composite.layout();
			}
		});
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	public static void main(String[] args) {
		new StackLayoutExample();
	}
}

⌨️ 快捷键说明

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