Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java swing background execution

 
aybee ryu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to make a progress monitor bar for a long execution. The program is basically trying to scan the local network (which takes about two minutes). I have a result class which prepares a JPanel that can be placed in the UI with the results. I want to have a neat progress bar for the whole process. I did make a ProgressMonitor object with a Task class and PropertyChangeListener as of the example in:

http://download.oracle.com/javase/tutorial/uiswing/components/progress.html

http://download.oracle.com/javase/tutorial/uiswing/examples/components/ProgressMonitorDemoProject/src/components/ProgressMonitorDemo.java


so currently it is like a fake progress bar which just based on the thread sleep time. Currently my approach is create another thread in action listener class that runs the result class but for some reason I can't call back the JPanel object from asynchronously.... I tried to used the ExecutorService with FutureTask but not sure whether I am using it the right way.

A general flowchart of my current app is like

UI-->scan button-->at actionlistener for scan button creation of the swingworker for task and executorservice


||1*|| is what i what to run parallel to the progress monitor

in the above code the scan button gets clicked and stays enabled until the scan is done but the progress monitor bar never shows up.

removing ||1*|| just shows up the progress bar but ofcourse the scan never took place.

ANY HELP IN CORRECT WAY OF SETTING IT UP or USE OF A DIFFERENT APPROACH WOULD BE GREATLY APPRECIATED!!
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may do the following.

1. Construct a Progress Bar control in Swing using JDialog (or whatever modal dialog you prefer)

2. In the JDialog have a boolean variable (boolean showProgress = false) to indicate whether the next progress state can be shown

3. In the JDialog have a Daemon Thread that checks the status of an operation, sets the showProgress = true (of course via a setShowProgress method), displays the new progress state, sets showProgress = false and goes to sleep
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic