gpt4 book ai didi

java - 获取 JTable 的真实选定值

转载 作者:行者123 更新时间:2023-11-30 09:12:21 29 4
gpt4 key购买 nike

我目前正在像其他人一样获取我的 jTable 的值:

String  d = jTable1.getModel().getValueAt( jTable1.getSelectedRow() , row ).toString();

问题是,现在我正在使用行排序器对我的 jTable 进行排序:

sorter = new TableRowSorter<TableModel>(modelo);
jTable1.setRowSorter(sorter);

private void filterTable(){
//If current expression doesn't parse, don't update.
try {
rf = RowFilter.regexFilter("(?iu)"+jFilter.getText(),0,1,2,3,4);//no filtrar la columna con imágenes porque hace cualquiera
} catch (java.util.regex.PatternSyntaxException e) {
return;
}
sorter.setRowFilter(rf);
}

问题:一旦表被过滤,函数 getSelectedRow 返回正确的行,但是 getModel 函数返回原始模型,而不是过滤后的模型...

问题:如何在过滤时从表中获取正确的值?

最佳答案

您可能需要使用 convertRowIndexToModel 将“行”值转换为模型索引值。

String  d = Table1.getModel().getValueAt(convertRowIndexToModel(jTable1.getSelectedRow()) , column ).toString();

关于java - 获取 JTable 的真实选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21604032/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com