• Post Reply Bookmark Topic Watch Topic
  • New Topic

Progress bar dialog sometimes doesn't display Swing components

 
Brian McGuinness
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Check out this excellent FAQ to understand (and figure out the solution) the problem http://www.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
  • 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.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!