Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do redraw the swt composite after clicking a button to change the content of that composite

Tags:

java

swt

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 trigger 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.

like image 876
user351687 Avatar asked May 27 '10 07:05

user351687


1 Answers

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.

like image 111
drstupid Avatar answered Oct 12 '22 22:10

drstupid