• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtable cell editing question

 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've run into some problem with JTable. All of my cells are editable, and I would like to provide an easy way to edit cells. First I used single click as the edit mode activator, but that is not too good, since whenever a user selects a row, it immediatlly starts to edit that cell. I also tried double click, but that method not too intuitive, and you have to make a lot of extra move. Is it possible to achieve somehow to start editing on the first click, but only if the row is already selected(not selecting by the click)?
BR,
Miklos
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've run into some problem with JTable.


Really? I can't imagine... ;) JTable is always a problem. At least for me. Powerful, but difficult.

Off the cuff, you would need to determine this in your table model's isCellEditable method. So in that method you would need logic to determine if the selected cell is part of an existing selected row. The problem with this is going to be timing. Does the row get selected before or after this method gets called? If it happens before, then your logic will always be true, which is a problem.
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Miklos Szeles wrote:..., but that method not too intuitive, and you have to make a lot of extra move.


Indeed.
That is one of the reasons why allowing the user to directly edit in the table is bad usability.
I always prefer a popup menu with a clearly defined "Properties" or "Edit" option. Invoking this action displays the user with a dialog with the editable fields.

With a non editable table, a JPopupMenu and JOptionPane you can make a user friendly and intuitive UI.
 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answers. I solved the problem. I have a common base class for all my cell editors and I overriden the isCellEditable method of the editor in which I compare the table's selected row and the row under the mouse.
BR,
Miklos
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic