繁体   English   中英

将JFace TableViewer添加到SWT表

[英]Add JFace TableViewer to SWT Table

在一个工具中,我正在工作,有一个表,我像这样添加:

public void addTable() {

    table = new Table(this, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);

    griddata = new GridData(GridData.FILL_BOTH);
    griddata.horizontalSpan = 2;

    table.setLayoutData(griddata);
    table.setHeaderVisible(true);

    final TableColumn tc1 = new TableColumn(table, SWT.LEFT);
    final TableColumn tc2 = new TableColumn(table, SWT.CENTER);
    final TableColumn tc3 = new TableColumn(table, SWT.CENTER);

    tc1.setText("ID");
    tc2.setText("Firstname");
    tc3.setText("Lastname");

    tc1.setWidth(30);
    tc2.setWidth(100);
    tc3.setWidth(100);

    final TableItem item1 = new TableItem(table, SWT.NONE);
    item1.setText(new String[] { "ABC", "Hatton", "Kentucky" });
    final TableItem item2 = new TableItem(table, SWT.NONE);
    item2.setText(new String[] { "DEF", "Warner", "Ohio" });
}

效果很好,但是现在,我想添加一个JFace表查看器,但是关于它的文档似乎只涉及TableLayouts,而不涉及Tables。 我以为TableViewer会被添加到表中?

同时想出了办法。 只是对行的第一个更改,如下所示:

        TableViewer viewer = new TableViewer(this, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); 
    table = viewer.getTable();

这样,您可以像以前一样收缩表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM