【问题标题】:Get the ArrayList index of an element after using a row filter on a JTable在 JTable 上使用行过滤器后获取元素的 ArrayList 索引
【发布时间】:2013-07-11 03:40:45
【问题描述】:

我有一个包含多个元素的 ArrayList,每个元素都包含下一个字段:

  • 姓名
  • 地址
  • 年龄

我有一个 JTable 来显示 ArrayList 中包含的信息。 我有一个 TableRowSorter 来根据某个字段过滤信息。

假设过滤后我只得到一个元素,因此 JTable 现在有一行。如何在原始 ArrayList 中获取该元素的索引?我是否必须再实现一种字段类型的“ID”?

【问题讨论】:

    标签: java swing arraylist filter jtable


    【解决方案1】:
    int viewIndex = 0; // the index in the table of the unique filtered row. 
    int modelIndex = table.convertRowIndexToModel();
    

    modelIndex 是支持表模型的列表中行的索引。

    【讨论】:

      猜你喜欢
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-02
      • 1970-01-01
      • 2019-05-21
      • 1970-01-01
      相关资源
      最近更新 更多