• Post Reply Bookmark Topic Watch Topic
  • New Topic

Progress Bar not working  RSS feed

 
Dave McNamara
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I'm trying to get a progress bar to work on my GUI.

This is what I have so far, the parameters are taken from another class that takes in an image in packets from a Raspberry Pi and stores them to a file on PC.



The println are printing out the correct values and they are being implemented in the methods, but nothing is happening in the GUI.

I have a thread setup in the GUI when a button is pressed


So the thread starts and image is then transmitted, does the progress bar need to be in that event handler?

Dave
 
Tony Docherty
Bartender
Posts: 3264
81
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your problem that the progress bar isn't visible or is it visible but not updating to show the progress?

I suspect your problem is down to the thread you are using to update the progress bar value. May I suggest you read the progress bar tutorial http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html and in particular the section near the bottom which talks about using a SwingWorker to run the background task and update the progress bar.
 
Dave McNamara
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,

The progress bar is visible but it doesn't do anything.

I've seen that tutorial and tried to follow it, but I can't figure out how to implement it in my code.

For instance if I put where my thread is created, it asks me to create a new method. In the tutorial, that is not needed.

Basically I don't understand how it works and for me at least, the tutorial is confusing.

Dave
 
Tony Docherty
Bartender
Posts: 3264
81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the tutorial there is a link to ProgressBarDemo.java which the code extracts are taken from. If you look at the whole class file you will see there is an inner class called Task whcih extends SwingWorker. In this class there is a doInBackground() method which is where you would do your downloading of the image packets and call setProgress() (which is a method inherited from SwingWorker and which sets the bound property 'progress').

In the demo, when the start button is pressed, a Task object is created and a PropertyChangeListener is added to it. The PropertyChangeListener's propertyChange() method is called whenever one of the Task objects bound properties is changed, checks if the changed property is named 'progress' and if so sets the progress bar to the value of progress.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!