[英]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.