水平滚动条更新

时间:2017-09-13 19:51:46

标签: eclipse-plugin swt

我正在乱搞SWT(对于一个PropertyPage),发现了一个小'bug'? 基本上,当我调整shell的大小以使其小于我的控件时,它会使scrollBar可见,这与预期的一样。虽然如果我调整控件的大小(当然它都是单个根的子控件),但不知何故,一个或多个父母不会更新更改,这会导致一些奇怪的行为。

当我的控件的大小增加时,它基本上会从shell中生长出来(不可见),而没有可见的Scrollbar。如果我调整shell的大小(小于初始大小),ScrollBar将变为可见,但仅限于初始大小而不是整个宽度。

当我的控件缩小尺寸时,它不会“打包”任何一个父级,这意味着我可以滚动到控制范围之外的空白。

也许值得一提的是,对我来说只有横向增长/缩小是一个问题,虽然我很确定垂直调整大小时会出现同样的问题

我的问题是,是否有解决方案/解决方法。我试过在各种父母和shell本身上调用Layout()pack(),但没有成功。现在我知道属性页面的一个父母(PreferenceDialog#PageLayout)使用了一个自定义(遗憾的私有)布局类型。也许这种行为来自这个实现?

编辑,根据要求提供MCVE

我假设有人知道如何为propertyPage设置,所以为了清楚起见,我只发布了createContents方法(覆盖org.eclipse.jface.preference.PreferencePage),以及一些辅助方法/字段应该重新创建一个设置可以观察到这种行为。基本上可以使用隐藏/取消隐藏列,并确保在需要不同的初始childSize(以测试增长和收缩)时重新打开

// static so you can re-open a the property/preference page for different initial sizes.
private static boolean  h1  = false;
private static boolean  h2  = false;
private static boolean  h3  = false;
private static boolean  h4  = false;

private Composite root;

@Override
protected Control createContents(Composite parent)
{
    // setup root
    this.root = new Composite(parent, SWT.NONE);
    this.root.setLayout(new GridLayout());
    this.root.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));

    Table table = new Table(this.root, SWT.SINGLE | SWT.VIRTUAL | SWT.BORDER | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    table.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));

    TableColumn c1 = new TableColumn(table, SWT.LEFT);
    c1.setMoveable(true);
    c1.setText("column 1");
    this.updateColumn(c1, h1);
    TableColumn c2 = new TableColumn(table, SWT.LEFT);
    c2.setMoveable(true);
    c2.setText("column 2");
    this.updateColumn(c2, h2);
    TableColumn c3 = new TableColumn(table, SWT.LEFT);
    c3.setMoveable(true);
    c3.setText("column 3");
    this.updateColumn(c3, h3);
    TableColumn c4 = new TableColumn(table, SWT.LEFT);
    c4.setMoveable(true);
    c4.setText("column 4");
    this.updateColumn(c4, h4);

    Button hide1 = new Button(this.root, SWT.PUSH);
    hide1.setText("Hide column 1");
    hide1.addListener(SWT.Selection, E -> {
        this.updateColumn(c1, h1 = !h1);
        this.resize();
    });

    Button hide2 = new Button(this.root, SWT.PUSH);
    hide2.setText("Hide column 2");
    hide2.addListener(SWT.Selection, E -> {
        this.updateColumn(c2, h2 = !h2);
        this.resize();
    });

    Button hide3 = new Button(this.root, SWT.NONE);
    hide3.setText("Hide column 3");
    hide3.addListener(SWT.Selection, E -> {
        this.updateColumn(c3, h3 = !h3);
        this.resize();
    });
    Button hide4 = new Button(this.root, SWT.PUSH);
    hide4.setText("Hide column 4");
    hide4.addListener(SWT.Selection, E -> {
        this.updateColumn(c4, h4 = !h4);
        this.resize();
    });

    for(int i = 0; i < 20; i++)
    {
        TableItem ti = new TableItem(table, SWT.NONE);
        ti.setText(new String[] {"c1:" + i, "c2:" + i, "c3" + i, "c4" + i});
    }

    return root;
}

protected void updateColumn(TableColumn c, boolean hide)
{
    if(hide)
    {
        c.setResizable(false);
        c.setWidth(0);
    }
    else
    {
        c.setResizable(true);
        c.setWidth(300);
    }
}

protected void resize()
{
    this.root.getDisplay().asyncExec(() -> this.root.getShell().layout(null, SWT.ALL | SWT.CHANGED));
}

0 个答案:

没有答案
相关问题