在SWT表中选择索引

时间:2017-04-24 04:08:25

标签: java checkbox swt

我有这个代码打印表中列的数据,但是如何获取另一列的值(我有3列)但它只打印第一列?

这是我的代码:

Table table = (Table) e.widget;
            if( e.detail == SWT.CHECK ) {
                System.out.println(e.item);
                if( table.indexOf( ( TableItem )e.item ) == table.getSelectionIndex() ) {
                    TableItem ti = ( TableItem )e.item;
                    ti.setChecked( !ti.getChecked() );
                }

            } else {
                TableItem ti = ( TableItem )e.item;
                ti.setChecked( !ti.getChecked() );
            }

输出:

TableItem {MIC0012345}

预期产出:

TableItem {MIC0012345, 2012, 2000} //(where 2012 and 2000 are remaining columns)

PS:我从stackoverflow获取代码

1 个答案:

答案 0 :(得分:1)

要获取表格项目的文本,请使用TableItem::getText()。在多列表格中,使用TableItem::getText(int)。 index参数从零开始,表示应检索文本的列。请注意,列按创建顺序编制索引,稍后重新排序列不会影响此方法。