【问题标题】:Selecting index in SWT table在 SWT 表中选择索引
【发布时间】:2017-04-24 13:51:31
【问题描述】:

我有这段代码可以打印表格中列中的数据,但我怎样才能获得另一列的值(我有 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 得到代码

【问题讨论】:

  • 您提到的从列中打印数据的代码在哪里?发布的代码是关于操纵选中状态的。

标签: java checkbox swt


【解决方案1】:

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

【讨论】:

  • 您到底尝试了什么?什么不起作用?编辑问题以发布您的代码并告知预期结果和实际结果。
  • 它希望我升级到 JRE 1.8 以便它可以工作,当我尝试你所说的时。
  • @abrakadabarahahastatags 使用ti.getText(0) 等。实际上不要使用TableItem::getText(0)
猜你喜欢
  • 2015-09-23
  • 2021-06-14
  • 1970-01-01
  • 2018-05-06
  • 1970-01-01
  • 2018-10-17
  • 1970-01-01
  • 1970-01-01
  • 2010-10-02
相关资源
最近更新 更多