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

updating JProgressBar  RSS feed

 
Altaf Ahmad
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I'm trying to update values in a JProgressBar based on user selection but I can't seem to get the updated values to reflect in the progress bar.
I looked up past threads and Sun's site, from which I derived that it had to be done using invokeLater(). But it doesn't work still. The value is being updated in the object, but it just doesn't update the GUI.
Here's my routine:

I'll appreciate if anybody could tell me what I'm doing wrong or where I could find relevant info! Any leads will be great!
Thanks,
Altaf
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what kind of calculations you are doing with the progress bar, but if your bar has a large range (i.e. 0-100), but your values are all very small ( i.e. 0 - 1 ), it won't be obvious when you update. It looks like the values in your table are floats, and you are multiplying them by 10. I think that means that your progress bar will go from 0 - 10... is this the case?

Here's some code I wrote to test your code. Everything seems to be working correctly... ?



-Nate
 
Altaf Ahmad
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nate!
I'll test the code out and put a reply back in. The values in the model are from 1 to 10 and are float values. So, I'm multiplying them by 10 ( e.g. 6.3 becomes 63) and having the progress bar have a range of 0 - 100.
I don't have to display a series of progression - just one value (like a percentage value showing how much some task had been completed at a point in time). I read that if you process some code in a loop, then only the last value will be shown in the swing control because of the event control/thread implemention. That would work fine for me since I have to display only one value, but it just wouldn't update the display at all.
Anyway, I'll try out what you wrote. Again, thanks a lot!
 
Altaf Ahmad
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nate,
It's working great now! I don't really know what caused it to change behavior though. Initially, I put sections of your code in my app and it started working after some tweaking. But when I removed it, it still worked. I took out the Runnable section, made the ListSelectionListener back into an anonymous class, but it just works now for some reason!
I'm still trying to locate what it exactly is that's making it work now!
But thanks a lot for your help! :-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!