0

I have built a small java application, it is for updating product price, quantity and special offers etc of products on a mysql database, using a csv file as input that I receive from a closed computer system in my fathers electrical retail business.

I have everything working, apart from a progress bar. I cannot for the life of me work out how to put a JProgressBar into my application because of its setup. I am relatively new to programming, in my first 6 months of a software engineering degree.

Basically, I have 3 classes: database (performs all interaction with mysql db) updater (interprets .csv file and interacts with database module to perform functions. It loops through array created from .csv file, and updates records) GUI (A basic gui, consisting of a JFrame, JPanel, buttons and text fields for database login and browsing for .csv file)

GUI creates instance of database, using its text fields as input, this is passed to and instance of updater class, also created by GUI.

Where in this project should I insert a progress bar, or what should i change about the setup of my project to allow this?

Your help will be greatly appreciated, im stuck and have searched the internet and cannot find a suitable way of making the progress bar functional for my situation.

And please go easy on me :P I know I have probably made fundamental errors in the setup of the whole thing lol

Thanks, Wilson.

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138

1 Answers1

0

Progress bar is surely GUI component, so where else it could belong? However it often shows the progress of something that is happening in your own, non Swing thread (doing too much in Swing thread freezes GUI controls). You cannot touch the progress bar from the non Swing thread directly. Use invokeLater or invokeAndWait to move it forward. To avoid memory trashing, it is possible to reuse the same Runnable, assigning the wanted progress to the inner field.

Runnable doProgress = new Runnable() {

   int progress = 0;

   public void run() {
       myProgressBar.setValue(progress++);
   }
};
// do something 
SwingUtilities.invokeLater(doProgress);
// do more
SwingUtilities.invokeLater(doProgress);
Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93