我想在SWT中使用布局,其作用类似于Swing的cardLayout.我的主要要求就像我有一个复选框并有2个SWT组.
并且基于复选框选择和取消选择需要分别在同一位置显示SWT组.
基于复选框状态,一次只能看到一个组.如何实现同样的目标.
你可以使用a StackLayout
来实现你想要的:
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();
}
Run Code Online (Sandbox Code Playgroud)
通过设置,StackLayout#topControl
您可以"移动" Control
到顶部.
归档时间: |
|
查看次数: |
712 次 |
最近记录: |