簡體   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