This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AbstractTableModel - how to highlight a particular row

 
ram shyam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using AbstractTableModel to display a table of data in the GUI. In this table, on double-clicking a particular row, a pop-up window is displayed and on pressing "ok", the pop-up is closed. After this, the highlighted row goes to the first row of the table. I would like to know how to highlight the same row which has been clicked, rather than highlighting the first row always (after the pop-up is closed, ie, after the call to setValueAt() of this table model). For eg., if there are more no. of rows in the table, after clicking a particular row in the bottom, opening and closing the pop-up window, the highlight again goes back to the first row after which I have to scroll down back to the previously clicked row.
Is it feasible to have the highlight on the same row?

Please clarify.

Thanks in advance!!
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ram shyam:
Hi all,
...Is it feasible to have the highlight on the same row?


The AbstractTableModel or rather any table model is not aware of selections. It is handled by the ListSelectionModel.
You will need to remember the current selection and reset it back after editing.
Take a look at JTable#getSelectionModel and ListSelectionModel#setSelectionInterval.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic