无法在向导页面中重新绘制 SWT 组合控件

huangapple go评论73阅读模式
英文:

Unable to redraw SWT Composite in a Wizard Page

问题

我有一个复合组件其中包含3个UI控件 - SWT GroupSWT TabFolder以及一个包含标签和链接的子复合组件在某些情况下SWT Group被隐藏起来我希望不要看到空白的空间而是重新绘制复合组件只显示SWT TabFolder和子复合组件而没有任何空白处
我使用composite.layout(true)但是当SWT Group被隐藏时仍然存在SWT Group的空白空间
有人可以帮我解决这个问题吗

TestComposite继承自Composite类{
    private Label childLabel;
    private Group group;
    private TabFolder tabFolder;
    private Button button;

    TestComposite(Composite 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);
        // 这应该重新绘制UI,只显示整个向导页面中的tabFolder和label,但在group的位置上仍然存在空白空间
        this.layout(true);
    }
}
英文:

I have a composite, which has 3 UI controls - SWT Group, SWT TabFolder, and a child composite that has a label and a link. In some use-cases the SWT Group is hidden, and I would like that the blank space is not seen instead the composite has to be redrawn and show only the SWT TabFolder and the child composite, without any space.
I'm using composite.layout(true), but still there is blank space of the SWT Group when it is made hidden.
Could someone help me solve this issue

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);
}
}

答案1

得分: 0

Group上设置GridData

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);
}
英文:

Set GridData on the Group

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

Use GridData.exclude to exclude/include the group in the layout:

public void enableVisibilityOfGroup(boolean visible) {
this.group.setVisible(visible);
GridData gridData = (GridData)this.group.getLayoutData();
gridData.exclude = !visible;
this.layout(true);
}

huangapple
  • 本文由 发表于 2020年9月4日 16:01:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/63737141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定