stacklayoutインスタンス

2123 ワード

swt   StackLayout 
2009-08-27 09:34
package swt.demo;

import org.eclipse.swt.SWT;

public class swtStackLayout {

/**
*  
*/
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
GridLayout gl = new GridLayout();
gl.numColumns = 3;
shell.setLayout(gl);//  
shell.setText("StackLayout   ( , )");
final Composite parent = new Composite(shell, SWT.NONE);
parent.setLayoutData(new GridData(GridData.FILL_BOTH));
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
parent.setLayoutData( gd );
final StackLayout sl = new StackLayout();
parent.setLayout(sl);
final Button bt1 = new Button(parent, SWT.PUSH);
bt1.setText(" ");
final Button bt2 = new Button(parent, SWT.CHECK);
bt2.setText(" ");
final Button bt3 = new Button(parent, SWT.RADIO);
bt3.setText(" ");
sl.topControl = bt1;

Button sbt1 = new Button(shell, SWT.PUSH);
sbt1.setText(" ");
sbt1.addListener(SWT.Selection, new Listener(){
@Override
public void handleEvent(Event event) {
sl.topControl = bt1;
parent.layout();
}

});
Button sbt2 = new Button(shell, SWT.PUSH);
sbt2.setText(" ");
sbt2.addListener(SWT.Selection, new Listener(){
@Override
public void handleEvent(Event event) {
sl.topControl = bt2;
parent.layout();
}

});
Button sbt3 = new Button(shell, SWT.PUSH);
sbt3.setText(" ");
sbt3.addListener(SWT.Selection, new Listener(){
@Override
public void handleEvent(Event event) {
sl.topControl = bt3;
parent.layout();
}

});

shell.setLocation(100, 100);
shell.setSize(500, 350);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();

}

}