SWT StackLayout布局 SWT(JFace)体验之StackLayout布局

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

SWT StackLayout布局 SWT(JFace)体验之StackLayout布局

  2021-03-17 我要评论
想了解SWT(JFace)体验之StackLayout布局的相关内容吗,在本文为您仔细讲解SWT StackLayout布局的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:SWT,StackLayout,布局,下面大家一起来学习吧。
测试代码如下:
复制代码 代码如下:

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();
}
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们