• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Question about table model listener

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 32
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic