Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a JTable row to an "unselected" state after selected any row in that table?

I'm developing a Java Swing application which contains a JTable. By default, while launching the application for the first time, the call to the method jtable.getSelectedRow() or jtable.getSelectedColumn() returns -1, which means that no row selected at that moment. After user clicked any row or column, the call to the method jtable.getSelectedRow() or jtable.getSelectedColumn() returns the appropriate values of selected rows & columns. What I actually need is that I want to set the selected row or column to -1 i.e. "no row or column selected state". How can I do this?

like image 556
Dinesh Avatar asked Oct 01 '11 05:10

Dinesh


People also ask

How do you get a value from a selected cell in a JTable?

To get a particular cell value, you can use the getValueAt(row, col) method in the JTable.

How do you clear a JTable row?

We can remove a selected row from a JTable using the removeRow() method of the DefaultTableModel class.

How can I tell if a row is selected in JTable?

JTable has a getSelectionModel() method which will give you a ListSelectionModel object. It tells you what rows are selected. You can add a ListSelectionListener to that via the addL..S..


1 Answers

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

like image 133
Hovercraft Full Of Eels Avatar answered Sep 21 '22 18:09

Hovercraft Full Of Eels