Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically deselect the currently selected row in a JTable (swing)?

Tags:

java

swing

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.

like image 474
alves Avatar asked Jun 19 '09 17:06

alves


People also ask

How do you clear a JTable row?

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.

How do I select a row in a table Swing?

You can do it calling setRowSelectionInterval : table. setRowSelectionInterval(0, 0); to select the first row.

What is JTable in Java Swing?

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.


1 Answers

There is a method on JTable called clearSelection. This, in turn calls clearSelection on the ListSelectionModel of the table and the column model.

like image 51
Avrom Avatar answered Oct 22 '22 06:10

Avrom