Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Editable JTable selection Versus editing row/cell  RSS feed

 
Peter Dennis
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have an editable JTable and was wondering if there was a way to distinguish between a row simply being selected opposed to the cell being edited?

At the moment I have:



I was hoping to find a way to only enable the save button (btnSave) when a cell had been double clicked in and therefore perhaps edited rather than simply selected/highlighted.

Is anyone able to tell me what sort of event I should be listening for or perhaps firing some sort of event via the table model? I have read some of these things after hours of googling but don't really understand how to proceed.

Many thanks,

Peter.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure there's an answer to your question. But to get that answer, it would be better if the question were asked in the Swing forum... so let's move it there.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I was hoping to find a way to only enable the save button (btnSave) when a cell had been double clicked in and
> therefore perhaps edited rather than simply selected/highlighted.

default is to start editing just by typing (no need for double-click), unless you add this line
table.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);

a tableModelListener might be one way

where dtm is a DefaultTableModel
 
Peter Dennis
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:>

a tableModelListener might be one way

> where dtm is a DefaultTableModel


Thank you Michael. That's what I was looking for.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!