欢迎来到工商注册核名查询系统!

Java编程

当前位置:主页 > 软件编程 > Java编程 >

SWT(JFace)体验之StackLayout布局

来源:本站原创|时间:2022-11-25|栏目:Java编程|

测试代码如下:

复制代码 代码如下:

package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class StackLayoutSample {
Display display = new Display();
Shell shell = new Shell(display);

final Button[] buttons = new Button[3];
public StackLayoutSample() {

final StackLayout stackLayout = new StackLayout();
shell.setLayout(stackLayout);
for(int i=0; i<buttons.length; i++) {
buttons[i] = new Button(shell, SWT.NULL);
buttons[i].setText("Button #" + i);
buttons[i].addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
Button nextButton = null;
for(int i=0; i<buttons.length; i++) {
if(buttons[i] == e.widget) {
if(i == buttons.length - 1)
nextButton = buttons[0];
else
nextButton = buttons[i+1];
}
}
stackLayout.topControl = nextButton;
shell.layout();
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}

stackLayout.topControl = buttons[0];
shell.setSize(200, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new StackLayoutSample();
}
}

更多Java编程

您可能感兴趣的文章

阅读排行

本栏相关

随机阅读

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 工商注册核名查询系统 版权所有