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

📄 stacklayout1.java

📁 SWTJFace篇项目源程序该项目包含 包含了Eclipse下构建swt的基本工程
💻 JAVA
字号:
package cn.com.chengang.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class StackLayout1 {
	public static void main(String[] args) {
		final Display display = Display.getDefault();
		final Shell shell = new Shell();
		shell.setSize(327, 253);
		// ---------创建窗口中的其他界面组件-------------
		shell.setLayout(new FillLayout()); // shell应用充满式布局

		// comp1容器使用堆栈式布局
		final Composite comp1 = new Composite(shell, SWT.BORDER);
		final StackLayout stackLayout = new StackLayout();
		comp1.setLayout(stackLayout);
		// 在comp1中创建两个组件
		final Button radio = new Button(comp1, SWT.RADIO);
		radio.setText("RADIO");
		final Button check = new Button(comp1, SWT.CHECK);
		check.setText("CHECK");

		// 在一个新容器中建立两个按钮用来控制上面两个组件的显示
		Composite comp2 = new Composite(shell, SWT.NONE);
		comp2.setLayout(new RowLayout());
		// 按钮button1控制RADIO的显示
		Button button1 = new Button(comp2, SWT.NONE);
		button1.setText("RADIO");
		button1.addSelectionListener(new SelectionAdapter() { // 单击事件
					public void widgetSelected(SelectionEvent e) {
						/*******************************************************
						 * --------下面两句是StackLayout中控制的关键------------*
						 ******************************************************/
						stackLayout.topControl = radio; // 显示Radio
						comp1.layout(); // 将界面刷新一下,否则显示上会没有任何反映的
					}
				});
		// 按钮button2控制CHECK的显示
		Button button2 = new Button(comp2, SWT.NONE);
		button2.setText("CHECK");
		button2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				stackLayout.topControl = check;
				comp1.layout();
			}
		});
		// -----------------END------------------------
		shell.layout();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}

⌨️ 快捷键说明

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