开发者

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 clemYxmBass StackLayoutSample {

Display displahttp://www.devze.comy = new Display();

Shell shell = new Shell(display);

final Button[] buttons = new Button[3];

public StackLayoutSawww.devze.commple() {

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()) http://www.devze.com{

if (!display.readAndDispat开发者_Python学习ch()) {

display.sleep();

}

}

display.dispose();

}

public static void main(String[] args) {

new StackL编程客栈ayoutSample();

}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新开发

开发排行榜