• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Progress bar dialog sometimes doesn't display Swing components

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wish to display a progress bar during a lengthy file translation process. When I created a ProgressBar class to do this and tested it with a short test program, it seemed to work fine. But when I add my ProgressBar class to a package containing various other classes, put that package in a jar file, and then execute the class using the progress bar from a menu in my main program, the frame of the progress bar shows up with the appropriate caption but the JLabel, JProgressBar, and JButton are not displayed. I have gone over my code numerous times and checked that the ProgressBar class constructor is getting the proper arguments, but I can't find anything wrong. I am completely mystified by this.



-----------------------------------------------------------------

// The progress bar works ok with this test program:



Any help would be appreciated.

I have also been wondering whether I need a separate instance of the border for each panel, or whether I can just create one instance and use it for all three panels.

--- Brian
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Check out this excellent FAQ to understand (and figure out the solution) the problem https://coderanch.com/how-to/java/JProgressBarDoesntUpdate
To get a broader perspective of the issue, you might also want to go through http://docs.oracle.com/javase/tutorial/uiswing/concurrency/
 
Brian McGuinness
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks for the pointers. I now have the progress bar working ok. What I did was to create a new interface to ensure that the class performing the lengthy file processing process would provide all of the query functions required by the ProgressBar to update its display:



I then added these functions to my file processing class, along with run().

Then I modified my ProgressBar class so that the Trackable class was one of the arguments to the constructor. The ProgressBar could then create a new thread for the Trackable class and start it. (I didn't want the user to have to click a Start button to start the process, since he had already selected a menu item and selected a directory from a FileChooser.)
After the main program launches the ProgressBar, control is immediately returned to it and the user can perform other operations, which is what I want. But now I have to figure out how to determine when the file processing class has finished executing so I can check its status and display an appropriate message, e.g. "installation aborted by user", "installation aborted due to file I/O error", "installation completed successfully", or whatever.

reply
    Bookmark Topic Watch Topic
  • New Topic