Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I can't get my progress dialog to update

 
Joe Areeda
Ranch Hand
Posts: 331
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The application has a command to upload bunch of files to a server over a ssh link. So I have the transfer done in a SwingWorker class, which fires property change events. I have a property change listener in a JDialog class that is supposed to update a progress bar and some text fields like which file it's on, how many bytes have been sent, transfer rate. Basically enough fluff to keep the user entertained during the transfer.

That part works fine as a println in the property change listener shows it is receiving regular (and correct) updates.

My problem is that I can't figure out how to get the dialog to draw all the items when they are updated.

I can get the progress bar to work with:


Although it does flash a little, it's acceptable.

If I try that with a JLabel it writes the new value over the old without clearing so it's soon unreadable.

I've tried, repaint(), paint(Graphics g), update (Graphics g). Paint and repaint don't seem to do anything.

Of course once the transfer finishes the dialog is repainted with the final values just fine.

It must be a simple call I'm missing. I don't know why I seem to always get the hard part working and spend hours on the simplest things.

Any help is appreciated.

Joe
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • Never call getGraphics() of a Component in client code.
  • Never invoke update(...) or any painting methods (other than repaint())directly, and never override the update() method for a Swing component.


  • As far as your problem is concerned, you really need to go through the tutorial on Concurrency in Swing. And didn't you read the API for JProgressBar? There's a link there to the tutorial on How to Monitor Progress which would have provided adequate guidance.
     
    Joe Areeda
    Ranch Hand
    Posts: 331
    2
    Java Netbeans IDE Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Darryl,

    I have read the Concurrency in Swing tutorial and the API and tutorials on progress bars. I thought I understood them but I'm obviously missing something. I have progress bars and updating tables and text fields working in other programs with repaint.

    My problem is calling repaint() leaves me with a blank dialog.

    I think it is time to write a simple demo program and see if I can find the underlying flaw in my logic.
     
    Joe Areeda
    Ranch Hand
    Posts: 331
    2
    Java Netbeans IDE Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Found it. Stupid, stupid bug.

    To start the worker thread I was calling myWorker.run(), changing that to myWorker.execute() and using repaint() works like it's supposed to.

    Joe
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic