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)?
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.
Miklos Szeles wrote:..., but that method not too intuitive, and you have to make a lot of extra move.
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.
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.
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps