aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Jtable cell editing question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jtable cell editing question" Watch "Jtable cell editing question" New topic
Author

Jtable cell editing question

Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

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.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jtable cell editing question