简体   繁体   English

Java swing-在jtable中取消选择选定的行

[英]java swing - deselect a selected row in jtable

I have an instance of JTable in my java swing application. 我的java swing应用程序中有一个JTable实例。 I want to deselect a selected row from this table. 我想取消选择该表中的选定行。 From This answer , JTable has provided clearSelection() method that deselect all selected rows in the table. 通过此答案JTable提供了clearSelection()方法,该方法取消选择表中所有选定的行。 But I want to deselect one row. 但我想取消一行 How can I do this? 我怎样才能做到这一点?

你有没有尝试过:

ListSelectionModel.removeSelectionInterval(int index0, int index1)?

是一个切换行的选择JTable中。

You can do this like that: 您可以这样做:

        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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM