Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you very much.
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • 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.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Manfred and all,
Manfred's idea is excellent.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!