简体   繁体   中英

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:

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

there is no need to convert the index if you know what you are searching.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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