[英]Remove List elements selected in JTable
我有一個基於使用List
表模型的JTable
,我想從List
刪除在此JTable
中選擇的元素,該JTable
是可排序的,因此當我選擇行時,我不能簡單地進行list.remove ,因為順序不同。 有解決的辦法嗎?
看一下JTable方法convertRowIndexToView
和convertRowIndexToModel
:
選擇總是根據JTable進行的,因此在使用RowSorter時,需要使用convertRowIndexToView或convertRowIndexToModel進行轉換。 下面顯示了如何將JTable的坐標轉換為基礎模型的坐標:
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
查看一些示例如何使用表#排序和過濾 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.