![](/img/trans.png)
[英]How to programmatically deselect the currently selected row in a JTable (swing)?
[英]java swing - deselect a selected row in jtable
我的java swing應用程序中有一個JTable
實例。 我想取消選擇該表中的選定行。 通過此答案 , JTable
提供了clearSelection()
方法,該方法取消選擇表中所有選定的行。 但我想取消一行 。 我怎樣才能做到這一點?
你有沒有嘗試過:
ListSelectionModel.removeSelectionInterval(int index0, int index1)?
見這是一個切換行的選擇JTable中。
您可以這樣做:
JTable table = new JTable(); // your table instance
TableModel dataModel = new DefaultTableModel(); // table model
DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); //table selection model
table.setModel(dataModel);
table.setSelectionModel(selectionModel);
int desiredRow = 0; // row which you want to deselect
selectionModel.removeSelectionInterval(desiredRow, desiredRow); // Removing selection for desired row
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.