如何在第二列或特定列中插入jface TreeViewer?

时间:2013-10-10 08:24:34

标签: java swt jface treeviewer

我试图在我的GUI的第二列(任务名称)中插入jface TreeViewer,但它与第一​​列(任务ID)合并。那么我怎样才能让控件将它从一列移到第二列。

1 个答案:

答案 0 :(得分:1)

使用GridLayout实现此目标的最简单方法是插入虚拟Label,占用TreeViewer前面的空格:

public static void main(String[] args)
{
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("StackOverflow");
    shell.setLayout(new GridLayout(3, true));

    /* Top row */
    new Button(shell, SWT.PUSH).setText("Button");
    new Label(shell, SWT.NONE);
    new Label(shell, SWT.NONE);

    /* Middle row */
    new Label(shell, SWT.NONE);
    new Button(shell, SWT.PUSH).setText("Button");
    new Label(shell, SWT.NONE);

    /* Bottom row */
    new Label(shell, SWT.NONE);
    new Label(shell, SWT.NONE);
    new Button(shell, SWT.PUSH).setText("Button");

    shell.pack();
    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }
    display.dispose();
}

产生这个:

enter image description here