簡體   English   中英

刪除在JTable中選擇的列表元素

[英]Remove List elements selected in JTable

我有一個基於使用List表模型的JTable ,我想從List刪除在此JTable中選擇的元素,該JTable是可排序的,因此當我選擇行時,我不能簡單地進行list.remove ,因為順序不同。 有解決的辦法嗎?

看一下JTable方法convertRowIndexToViewconvertRowIndexToModel

選擇總是根據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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM