• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about table model listener  RSS feed

 
Jon Swanson
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a table that has three columns and for the second two columns, the user can enter data into one or the other column and the program fills in the data for the other column. That all works, but then I added an observer which is given data from the table when a complete row is entered. I find that I am sending the data once for each row in the table, rather than once for each change in the table.

Here is the basics of my table model listener:



The problem is when I call methods to update the rows in the table.



I know that by setting the values in the column under program control I am firing off my table model listener (I get one even if I comment them out). None of those intermediate results will be correct. What I was hoping was that I could-

Get the user data
Update the table based on the user data
Build the object for the observation
Set the value of the observation (once)

Did I structure this problem wrong? Or do I need some sort of hack like setting a flag before calling the updateWeightPercent() routine and unsetting it when it is finished? I'm leaning that way, but would rather know the right way to handle this sort of thing.

I'm thinking that I have not organized the problem correctly, I'm not exactly sure why I don't end up in some sort of infinite loop where I call the updateWeightPercent and as soon as it updates a row, it calls itself again. But that doesn't happen. Yet the observable does get updated multiple times.

 
Alexander Kober
Ranch Hand
Posts: 32
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon Swanson wrote:Did I structure this problem wrong? Or do I need some sort of hack like setting a flag before calling the updateWeightPercent() routine and unsetting it when it is finished? I'm leaning that way, but would rather know the right way to handle this sort of thing.


That is actually a feasible approach for what you're trying to do, adding a flag is not a 'dirty hack'. You should, however, make sure to make this flag volatile if you're doing your updates from a worker thread to avoid threading issues.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!