Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

addCellListener problem  RSS feed

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am using addCellListener in my JTable and something strange is going on. When I edit a cell in a table, the listener does not seem to be called the first time. However, when I update cell the next (n) times Listener is being called but twise. Can someone help?
Here is the code for the Listener:
==================================

thanks,
Alex
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you adding a table model listener in a method of the CellEditorListener? Why not just add the TableModelListener to the table model once right after the table is created?

You aren't getting a call the first time because you are adding the TableModelListener *after* you edit the value. You are getting n-1 calls for the next n times you edit because you are adding a new TableModelListener *every time* you edit a cell using the specified cell editor.
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!
I did the following, but now Listener is not called at all.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you replacing the model used in the table after you add the listener or anything? This code should work fine...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!