• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I can't get my progress dialog to update

 
Ranch Hand
Posts: 334
2
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 334
    2
    Netbeans IDE Tomcat Server Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 334
    2
    Netbeans IDE Tomcat Server Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    reply
      Bookmark Topic Watch Topic
    • New Topic