简体   繁体   English

jTable从过滤的行中获取数据

[英]jTable get data from filtered rows

I want to retrieve some data from a filtered row. 我想从过滤的行中检索一些数据。
This is how i filter my table : 这是我过滤我的表格的方式:

    String makeText = makeFilterCombo.getSelectedItem().toString();
    if (makeText == "All") {
        makeText = "";
    }

    String numar = getEssRegex();

    String impact = impactBox.getSelectedItem().toString();
    if (impact == "All") {
        impact = "";
    }

    TableModel model;
    model = jTable1.getModel();
    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    jTable1.setRowSorter(sorter);

    List<RowFilter<Object, Object>> rfs = new ArrayList<RowFilter<Object, Object>>(2);
    rfs.add(RowFilter.regexFilter(makeText, 2));
    rfs.add(RowFilter.regexFilter(numar, 5));
    rfs.add(RowFilter.regexFilter(impact, 9));

    RowFilter<Object, Object> af = RowFilter.andFilter(rfs);

    sorter.setRowFilter(af);    

And this is how i try to get a value from a filtered row: 这就是我尝试从过滤行中获取值的方法:

    int f = search(connectedCarIndex);

    connectedImage1 = jTable1.getModel().getValueAt(jTable1.convertRowIndexToModel(f), 10).toString();
    connectedImage2 = jTable1.getModel().getValueAt(jTable1.convertRowIndexToModel(f), 11).toString();
    connectedImage3 = jTable1.getModel().getValueAt(jTable1.convertRowIndexToModel(f), 12).toString();

    System.out.println(connectedImage1 + "-------" + connectedImage2 + "------" + connectedImage3);    

But none of this works ? 但这一切都不起作用?
Can anybody help me ? 有谁能够帮助我 ? The code works and i can see the connected image name if the rows are shown 代码工作,如果显示行,我可以看到连接的图像名称

int f = search(connectedCarIndex);

I have no idea what the search(...) method does. 我不知道搜索(...)方法的作用。

If you are searching the data that is displayed in the table then you would just use: 如果您正在搜索表中显示的数据,那么您只需使用:

table.getValueAt(...);

If you are searching all the data that is stored in the TableModel then you would use: 如果要搜索存储在TableModel中的所有数据,那么您将使用:

table.getModel().getValueAt(...);

there is no need to convert the index if you know what you are searching. 如果您知道要搜索的内容,则无需转换索引。

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

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