I want Layout in SWT which acts like cardLayout of Swing. My Main requirement is like I have a checkBox and have 2 SWT groups.
And based on checkbox selection and deselection need to show the SWT groups respectively in the same position.
Precisely only one group must be visible at a time based in checkbox state. How to achieve the same.
You can use a StackLayout
to achieve what you want:
private static boolean buttonOnTop = true;
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new FillLayout());
Button switchButton = new Button(shell, SWT.NONE);
switchButton.setText("Switch");
final StackLayout layout = new StackLayout();
final Composite content = new Composite(shell, SWT.NONE);
content.setLayout(layout);
final Button button = new Button(content, SWT.PUSH);
button.setText("Button");
final Label label = new Label(content, SWT.NONE);
label.setText("Label");
layout.topControl = button;
switchButton.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event arg0)
{
layout.topControl = (buttonOnTop) ? label : button;
content.layout();
buttonOnTop = !buttonOnTop;
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
By setting StackLayout#topControl
you can "move" your Control
to the top.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With