I am new to SWT. The project I am working on has a main composite with 3 children composite on it. the Upper composite consist with buttons, and the middle composite is for displaying content, and the lower composite is for other purpose. What has to happen is when i click a button in the upper composite, it has to tr开发者_如何学运维igger the content change in the middle composite. this is the code i am used to do this
public void widgetSelected(SelectionEvent e) {
/* Retrieve the contents that are currently in middle composite*/
Composite currentCenterComposite = EMWindow.getCenterCompsiteState();
/* Retrieve the main composite*/
Composite outerComposite=EMWindow.getOuterCompsiteState();
if ((currentCenterComposite != null) && (!currentCenterComposite.isDisposed())) {
/* Remove children that are already laid out */
Object[] children = currentCenterComposite.getChildren ();
for (int i = 0; i < children.length; i++) {
((Composite)children[i]).dispose();
}
}
currentCenterComposite = new CenterComp(currentCenterComposite);
GridData gd_centerComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gd_centerComposite.minimumHeight = 50;
currentCenterComposite.setLayoutData(gd_centerComposite);
currentCenterComposite.layout(true);
//currentOuterComposite.layout();
outerComposite.layout(true);
}
The Problem right now is after i click the button and above code was executed, nothing seems happen until i resize the GUI, then the content in the middle composite will appear.
Composite.layout() = "If the receiver has a layout, asks the layout to lay out"
Note that Layout and LayoutData are two different things. The LayoutData tells the Composite how to behave on the parent. The Layout tells the Composite how to arrange its children. In your case, you are NOT setting a layout on currentCenterComposite, therefor calling layout() has no effect.
Try to also set a Layout on your composite.
精彩评论