GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes I can't get my progress dialog to update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "I can Watch "I can New topic
Author

I can't get my progress dialog to update

Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 318
    
    2

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


It's not what your program can do, it's what your users do with the program.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4575
    
    5

  • 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.


    luck, db
    There are no new questions, but there may be new answers.
    Joe Areeda
    Ranch Hand

    Joined: Apr 15, 2011
    Posts: 318
        
        2

    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

    Joined: Apr 15, 2011
    Posts: 318
        
        2

    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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: I can't get my progress dialog to update