Here's a tricky problem, which I think may be a
thread issue, for reasons noted below (but I could be wrong, so I'm posting in this forum).
I have a table (JClass LiveTable, but I think that's moot). The last price field in the table is constantly changing. When it changes, I need to make the text green, if its equal to or above a certain (fixed) value, opening value, and red if its below it.
The
listing corresponds to a "line" of data backing the table. The
PriceWatcher has the two numbers, the last value and the opening value.
Assuming the ticks aren't null (they never are except when I first create the table), I select a style, red or green, for the text. It seems to work.
But we want to make it even better, by first bolding the text for 1 second after the price changes. The modified code to do this is below (at the bottom of the method.
I basically save off the styles (either for red or green) and start the thread. The problem is, it doens't work correctly. The colors are no longer consistent, i.e it's red when it should be green and visa-versa. However, when I look at the comparison in the print statement, it is correct!
My theory is, because the comparison is correct, and because it work without the bolding, the problem is in the thread. Specifically, I'm thinking I'm not understanding something about how the thread works wrt the method. The changes are happening very quickly, i.e. a few different rows will be changed in under a second. I'm thinking somehow the method is getting called multiple times, but there is a single row value be shared across them. (I'm not 100% certain what it means to make the row variable final in the method, but that seemed necessary to get the thread to accept the value.)
Any thoughts, ideas, or explainations?
--Mark