I want to programmatically deselect the currently selected row (or rows) in a JTable.
Basically I want the opposite of this:
JTable table = ...; table.setRowSelectionInterval(x,x); I tried (with little hope) using:
table.setRowSelectionInterval(-1,-1) or
table.setRowSelectionInterval(1,0) but it doesn't work.
If using the DefaultTableModel , just set the row count to zero. This will delete the rows and fire the TableModelEvent to update the GUI. JTable table; … DefaultTableModel model = (DefaultTableModel) table.
You can do it calling setRowSelectionInterval : table. setRowSelectionInterval(0, 0); to select the first row.
The JTable class is a part of Java Swing Package and is generally used to display or edit two-dimensional data that is having both rows and columns. It is similar to a spreadsheet. This arranges data in a tabular form.
There is a method on JTable called clearSelection. This, in turn calls clearSelection on the ListSelectionModel of the table and the column model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With