File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Java swing background execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java swing background execution" Watch "Java swing background execution" New topic
Author

Java swing background execution

aybee ryu
Greenhorn

Joined: Jul 19, 2011
Posts: 6
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

Joined: Mar 18, 2011
Posts: 312

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


S.D. MADHAN
Not many get the right opportunity !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java swing background execution