• 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 doesn't recognise update until field is exited

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fact that JTable only calls the SetValueAt() method when a user leaves an updated cell is causing me a problem. If the user closes the application before tabbing out of the cell (or clicks onto another tab of a tabbed pane) , my code in SetValueAt() is never executed.

I'd appreciate any suggestions on the best way to deal with this. Do I need to set up a listener to detect whenever any character is modified rather than waiting for the user to leave the cell?

Thanks,
Keith
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try adding a focusListener to the JTable and call setValueAt yourself when focus is lost.
 
Keith L
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I was moving in that direction myself. The problem with calling SetValueAt()myself is that I need to give it the row and column of the cell currently being edited. I'm not sure where to get that.

My thought was to set up a focus listener and then call:

table.getCellEditor().stopCellEditing();

This is almost working but I get a null pointer error if the focus is lost when a cell has been selected but not edited.
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Presumably it is the CellEditor that is null if the cell isn't being edited (though the API docs don't say this). In that case I would just use this, which looks a bit nicer than catching an exception IMHO:
 
Keith L
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This works:

if ( table.isEditing())
table.getCellEditor().stopCellEditing();

but I came across this which looks as though it might be simpler:

envtable.editingStopped(new ChangeEvent());
 
reply
    Bookmark Topic Watch Topic
  • New Topic