我有一个基于表模型的 JTable
,它使用 List
,我想删除在此 JTable
中选择的元素,从 List
中,JTable
是可排序的,因此当我获取选定的行时,我不能简单地 list.remove,因为顺序不同。有办法解决这个问题吗?
最佳答案
看看JTable方法convertRowIndexToView
和convertRowIndexToModel
:
The selection is always in terms of JTable so that when using RowSorter you will need to convert using convertRowIndexToView or convertRowIndexToModel. The following shows how to convert coordinates from JTable to that of the underlying model:
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
关于java - 删除 JTable 中选定的列表元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24317216/