我有一个JTable基于表模型,使用一个List,我想删除在这里选择的元素JTable,从List,JTable是可排序的,所以当我得到选定的行,我不能简单地list.remove,因为顺序是不同的.有什么想法解决这个问题?
看看JTable方法convertRowIndexToView和convertRowIndexToModel:
选择始终是JTable,因此在使用RowSorter时,您需要使用convertRowIndexToView或convertRowIndexToModel进行转换.以下显示如何将坐标从JTable转换为底层模型的坐标:
Run Code Online (Sandbox Code Playgroud)int[] selection = table.getSelectedRows(); for (int i = 0; i < selection.length; i++) { selection[i] = table.convertRowIndexToModel(selection[i]); } // selection is now in terms of the underlying TableModel
有关示例,请查看如何使用表#排序和筛选.