• 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

Why change to a cell is not activated until i click somewhere else?

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Here is my question about JTable. I register an action listener to my JFrame which contains a JTable. I use a button to reponse to the click action. If i edit a cell in the table and i click the button, the new content is not detected. The content is detected/updated only when i click any other cell in the table. How can i detect the new content in a cell even the cell is still focus? Thanks
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of using an ActionListener. try a TableModelListener.
ActionListener only fires when you leave the cell.
Mark
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much.
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I find that TableModelListener also does not give me the last updated cell value if i do not leave the cell. In other words, i still have to click at somewhere else in order to allowed edited content to be captured by the event listener. Do you have any other idea? I

Thanks.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi SoonAnn,
I have had problems with this in the past. I think it is just the way the JTable was designed because the table doesn't change the model data until the user has specified completion either through lostFocus or enter key.
You can programmatically move the editing cell to some other cell and then back again. Visually nothing changes and the table model gets updated with the user none the wiser.
Something like the following should work in most cases:

Regards,
Manfred.
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Manfred and all,
Manfred's idea is excellent.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic