How to make a JTable row in the “unselected” state after selecting any row in this table?

I am developing a Java Swing application that contains JTable . By default, when you start the application for the first time, calling jtable.getSelectedRow() or jtable.getSelectedColumn() returns -1, which means that no row is selected at this point. After the user clicked on any row or column, calling the jtable.getSelectedRow() or jtable.getSelectedColumn() method returns the corresponding values ​​of the selected rows and columns. What I really need is that I want to set the selected row or column to -1, that is, "there is no row or column state." How can i do this?

+8
java select swing jtable
source share
1 answer

The JTable clearSelection method will do what you want - clear the selection of all selected rows and columns of the table. The JTable API is the place to look for such methods.

+14
source share

All Articles