• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jtable cell editing question

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic