0

In my editor, I have a composite containing a label control right at the top which flashes informative message in red colour whenever the user enters erroneous inputs in any of the below lying fields. The text keeps changing dynamically depending on user's input. I am able to achieve the effect of displaying red coloured text on erroneous inputs and displaying nothing in the label for correct inputs.

But, I want that when there is no error to display in the label composite, the rest of the below fields shift up in display. And when there is error to display, the error should appear in it's place(at the top of all other fields) pushing the other fields down.

Is there a way to achieve this effect without redrawing all the controls again?

4

1 回答 1

0

是的,打电话layout (true)给家长。

例如,我有一个视图,顶部有一个搜索栏,可以切换其可见性。我有一种创建搜索组合的方法和一种删除它的方法:

private void createNameSearchBar () {
    mySearchControl = new CardSearchControl (myViewComposite, SWT.NONE);
    mySearchControl.setSearchListener (this);
}


private void disposeNameSearchBar () {
    mySearchControl.dispose ();
    mySearchControl = null;
}

private CardSearchControl mySearchControl = null;
private Composite myViewComposite;
private boolean mySearchBarState;

要隐藏或显示搜索栏控件,我调用此方法(myViewComposite 是拥有搜索栏和所有其他控件的顶级控件):

public void setSearchBarState (boolean show)  {
    mySearchBarState = show;

    if (myViewComposite == null  ||  myViewComposite.isDisposed ())
        return; // no work to do

    if (mySearchBarState  &&  mySearchControl == null)  {
        createNameSearchBar ();
        mySearchControl.moveAbove (null);
        myViewComposite.layout (true);
    }  else if (!mySearchBarState  &&  mySearchControl != null)  {
        disposeNameSearchBar ();
        myViewComposite.layout (true);
    }
}
于 2009-11-03T19:45:36.363 回答