SWT(JFace)体验之StackLayout布局

2019/7/7 19:30:03

本文主要是介绍SWT(JFace)体验之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();
}
}


这篇关于SWT(JFace)体验之StackLayout布局的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程