无法在向导页中重新绘制swt组合

lrpiutwd  于 2021-07-05  发布在  Java
关注(0)|答案(1)|浏览(272)

我有一个组合,它有3个ui控件-swt group、swt tabfolder和一个子组合,子组合有一个标签和一个链接。在一些用例中,SWT组是隐藏的,并且我希望空白空间不被看到,相反,复合物必须重新绘制,只显示SWT TabF文件夹和子复合,没有任何空间。我使用的是composite.layout(true),但是当swt组被隐藏时仍然有空白。有人能帮我解决这个问题吗

TestComposite extends Composite{
   private Label childlabel;    
   private Group group;
   private TabFolder tabFolder;
   private Button button;

    TestComposite(Compossite parent){
       super(parent, SWT.NONE);
       setLayout(new GridLayout(1, true));
       setFont(parent.getFont());
       setBackground(parent.getBackground());
       GridDataFactory.fillDefaults().grab(true, true).applyTo(this);
       createControl();
    }

    public void createControl() {

    this.group = new Group(this, SWT.SHADOW_IN);       
    this.group.setSize(this.getDisplay().getActiveShell().getSize());        
    this.button = new Button(this.group, SWT.PUSH); 
    GridDataFactory.swtDefaults().applyTo(this.button);

    this.tabFolder = new TabFolder(this, SWT.TOP);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, 
    true).applyTo(this.tabFolder);

    Composite childComposite = new Composite(this, SWT.NONE);
    childComposite .setLayout(new GridLayout(2, false));
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.LEFT, 
    SWT.TOP).applyTo(childComposite );
    this.childLabel = new Label(childComposite, SWT.NONE);
    GridDataFactory.swtDefaults().grab(true, false).applyTo(childlabel);

    setInput(abc);
    enableVisibilityOfGroup(false);
}

public void enableVisibilityOfGroup(Boolean visible){
    this.group.setVisible(visible);
    // this shoudl redraw the UI and shown only tabFolder and label in the
    // whole wizard page, but there is blank space in place of group
    this.layout(true);
}

}
lmvvr0a8

lmvvr0a81#

GridDataGroup ```
GridDataFactory.swtDefaults().applyTo(this.group);

使用 `GridData.exclude` 要在布局中排除/包括组,请执行以下操作:

public void enableVisibilityOfGroup(boolean visible) {
this.group.setVisible(visible);

GridData gridData = (GridData)this.group.getLayoutData();
gridData.exclude = !visible;

this.layout(true);

}

相关问题