我正在研究SWT在我的要求中,我希望在单击按钮时在复合的相同位置显示两种不同的形式,因此我使用StackLayout创建了一个Composite。我可以相应地渲染两种形式(具有不同形式的子复合),但问题是我的一种形式是橙色背景而另一种形式是透明的。 当我从透明移动到橙色复合材料时,它可以正常工作。但是当我从Orange移动到透明复合材料时,橙色复合材料在背景中仍然可见。当我切换到不同的窗口并移回我的视图时,它只显示透明复合材料,这是我的要求。我尝试但是无法在点击按钮时立即获得透明复合.Below是我的代码片段。
\\ the container composite with stacklayout.
bottomComposite = new Composite(parent, SWT.NO_BACKGROUND);
bottomCompositLayOut = new StackLayout();
bottomComposite.layout(true);
\\first form composite
formComposite = new Composite(bottomComposite, SWT.NONE);
GridLayout formLayout = new GridLayout(3, false);
formLayout.marginTop = 10;
formLayout.horizontalSpacing = 20;
formComposite.setLayout(formLayout);
formComposite.setBackground(orange);
GridData formCompositeData = new GridData();
formCompositeData.widthHint = 800;
formCompositeData.heightHint = 200;
formCompositeData.horizontalAlignment = SWT.CENTER;
formComposite.setLayoutData(formCompositeData);
\\Second transparent composite
progressComposite = new Composite(bottomComposite, SWT.NO_BACKGROUND);
GridLayout progressLayout = new GridLayout(1, false);
progressLayout.verticalSpacing = 1;
progressLayout.marginTop = 1;
progressComposite.setLayout(progressLayout);
//progressComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
GridData progressCompositeData = new GridData();
progressCompositeData.widthHint = 800;
progressCompositeData.heightHint = 200;
progressCompositeData.horizontalAlignment = SWT.CENTER;
progressComposite.setLayoutData(progressCompositeData);
//Works properly when I am doing
bottomComposite.topcontrol = formComposite;
//Shows other form when I made transperent composite to top control.
bottomComposite.topcontrol = progressComposite;