Trouble in implementing a progress monitor?

I need a lot of calculation when I click start button, so, I made a thread using SwingWorker class, this thread is responsible for the calculation. I need a progress monitor to display the progress of the calculation, so, do I need another thread to do it? How can I do it? Any suggestion is great appreciated.
The following is the schetch of my class.
// this class do the calculation
// these stuff is within my button listener
MyClass my = new MyClass(...);
my.go();
// stuff in go() method of MyClass is :
final SwingWorker worker = new SwingWorker() {
void construct(){
// Do calculation
void finished(){}
How to add another thread to do progress monitor stuff?

I assume your concern is about updating JProgressBar's value property from your SwingWorker's thread. Since you're using SwingWorker I assume you know the whole "Swing is not Thread-Safe" drill. If only Sun would specify a few more methods to be thread-safe, like JProgressBar's setValue! After all, isn't the raison d'etre of a progress bar to show how another thread is doing? Oh well, why not use my code, below. You don't need another thread, you only need to access Swing from the EDT, hence my calls to InvokeLater. And in case the progress updates come fast and furious, my code coalesces those events. Enjoy -- Nax.
class Updater implements Runnable {
     public Updater(JProgressBar jpb) {
          this.jpb = jpb;
     public void run() {
          int v;
          synchronized(this) {
               queued = false;
               v = val;
          jpb.setValue(v);
     public void update(int v) {
          boolean go = false;
          synchronized(this) {
               val = v;
               if (!queued) {
                    queued = true;
                    go = true;
          if (go)
               SwingUtilities.invokeLater(this);
     private boolean queued;
     private int val;
     private final JProgressBar jpb;

Similar Messages

  • Progress Bar or Progress Monitor for a system command

    Hello,
    I am running a DOS copy command in a Java Swing application. I understand that I
    can implement a Progress Bar or a Progress Monitor if I open the first file, read it,
    and write to a second file. But if I have a need to use the DOS copy command,
    is there a way to implement a Progress Bar or a Progress Monitor for it. If there is,
    could you please point me to some example code?
    Thank you,
    Chris

    Hello Chris,
    you would have to write some native code which peeks or watches the DOS process and its progress. Surely not an easy task. But without that information, how will you set values for the ProgressMonitor?
    What you could do, however, is showing an Indeterminate JProgressBar at DOS process start and make it disappear at process end.

  • What's wrong with my Progress Monitor and how do I fix it?

    Hello,
    My progress monitor fails to draw its insides, except when the task is already finished
    Inside a class that extends SwingWorker<Void, Void> ...
         @Override
         public Void doInBackground() throws Exception
              try
                   this.progressMonitor = new ProgressMonitor(jPanelControl,
                             "Running a Long Task",
                             "", 0, data.size());
                        //jPanelControl.invalidate();
                        progressMonitor.setMillisToPopup(500);
                        progressMonitor.setMillisToDecideToPopup(100);
                   this.doProcess();
              catch (Throwable e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              return null;
         }doProcess goes on a little journey until we get to:
                      progressMonitor.setNote("Importing " + this.title);
            for (int i = start; i < this.data.size(); i++)
                   progressMonitor.setProgress(i);
                            //doing stuff each iterationQuickly after loading begins the box appears but it's not drawing the graphics inside the window (see screenshot for more)          
    btw: That white background is Java3D, could it be interfering with the way Swing updates graphics?
    Edited by: loza on Aug 25, 2009 4:03 AM

    Hi,
    take a look at [this sample from java tutorial|http://java.sun.com/docs/books/tutorial/uiswing/examples/components/ProgressBarDemoProject/src/components/ProgressBarDemo.java] ;
    Regards,
    Alan Mehio
    London,UK

  • Need configure guide for job progress monitor in JSM

    Hello Guys,
    I have received  an requirement to setup job progress monitoring in JSM(job schedule monitor).i have done my search in Google for configuration guide, but i could not find it.
    My Requirement:- i need to monitor the jobs progress(running on manage system) which consists on nearly 10 setps.End user need to monitoring the job progress  using PI diagram.
    Guys  if any one of you have done this setup please help me with configuration setps.
    Please provide your inputs on this.
    Regards,
    Pavan

    Hi Pavan,
    That should have been my place from where I would have start
    I hope Jansi, Prakhar or Karthik can redirect you on this.
    Meanwhile, If I get any thing, I will share it.
    Regards

  • Adding progress Monitor

    HI All,
    I have been working with reading an XML file through a local path, and sending it to the server via a web service
    The code is something like this:-
    String strnewpath = vecPathPLS.elementAt(insel).toString();
    FileInputStream finpStream = new FileInputStream(strnewpath);
    len = finpStream.available();
    for(int i=1; i <= len; i++)
                                  postxml = postxml+(char)finpStream.read();
    //This postxml will be sent as a parameter to the webservice method"post"My problem is I have to add a progress monitor or a progress bar while the file input stream is getting read in postxml.
    I dont know how this can be done.
    Any help and code snippets from your side will really help me out
    Thanks a lot
    Shikha

    this thread from a couple of days back might help
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=708732

  • Deployment Progress Monitor

    Once I start the application using "Debug" or "Run", the Deployment Progress Monitor will show the messages:
    "Starting Application" ...
    "asadmin -start-domain ...."
    and then this status window will be kept open even with "Automatically close" set. As result of that, the Web browser is never opened by Creator.
    There isn't any error message in server.log. The server is started and I can open the first page typing the URL. I checked and the path to the default browser is correctly set in the Creator "options" setting.
    There are two problems that result of the above situation:
    1) The browser will not be open with the first page;
    2) Even that I use "Debug" to start the application, I can't debug it, breakpoints will not work;
    Thxs

    Yes, if one starts the app server outside Creator. It will be much more stable and the monitor window will not hang.
    Also, it is good to check doman.xml. Sometimes the application name is not set correctly in context-name.
    Finally, If Creator begins to not be able to start the App Server, one also canjava, javaw, rundll and extra runide process in the Task Manager.
    Thanks.

  • How to use  Progress Monitors?

    how to use Progress Monitors?
    in the name of god
    hi friends
    i have a problem. I am writing a program that read data from a file record by record and store to a database. my problem is here that i want add a progress monitor that when the program is doing its work it appear. I use ProgressMonitorInputStream class but it can not work well. It appear and read file record by record and store in table of database but its progress don’t move and do nothing. I know that I have a tiny problem in use this class. Please guide me.
    i put my codes below.
    best regards
    *////this is an event that invoke my classes*
    private void readbtnActionPerformed(java.awt.event.ActionEvent evt) {                                       
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setCurrentDirectory(fileName);
            //filtering file extension
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Text file", "txt");
            fileChooser.setFileFilter(filter);
            //fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            int result = fileChooser.showOpenDialog(this);
            if (result == JFileChooser.APPROVE_OPTION) {   //if choose ok button
                fileName = fileChooser.getSelectedFile();
                ReadTextFile readFile = new ReadTextFile(fileName);
                readFile.openFile();
                readFile.readRecord();
                *//readFile.closeFile();       //if  this line enable this message appeare "Scanner closed" .why?*      
                readFile.closeFile();
            } else //if choose cancel button
                result = 0;     //do nothing
    */////this is readFile class and invoke data access class and insert data in my database*
    public class ReadTextFile {
        private Scanner input;
        private File fileName;
        private int i = 1;
        DataAccess dal = new DataAccess();                     //new a defined my class
        AcountRecord record = new AcountRecord();
        public ReadTextFile(File n) {       //Constructor
            fileName = new File(String.valueOf(n));
            this.openFile();
        private void setRecord(String val) {
            try {
                record.setId(Integer.parseInt(val.substring(1, 5)));
                record.setTime(Integer.parseInt(val.substring(8, 12)));
                record.setDate(Integer.parseInt(val.substring(15, 21)));
                record.setMode(val.substring(24, 26));
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "ÇäÊÎÇÈ ÔãÇ äÇÏÑÓÊ ÇÓÊ.","Set Record Method",JOptionPane.ERROR_MESSAGE);
        public void openFile() {
            try {
                input = new Scanner(fileName);
            } catch (FileNotFoundException e) {
                JOptionPane.showMessageDialog(null, "ÇäÊÎÇÈ ÔãÇ äÇÏÑÓÊ ÇÓÊ.","Open File Method",JOptionPane.ERROR_MESSAGE);
        public void readRecord() {
            new Thread() {
                private Component _Main;
                @Override
                public void run() {
                    try {
                        input = new Scanner(fileName);
                        InputStream in = new FileInputStream(fileName);
                        ProgressMonitorInputStream pm =
                                new ProgressMonitorInputStream(_Main, "reading the file", in);
                        ProgressMonitor pmo = pm.getProgressMonitor( );
                        pmo.setMaximum( (int) fileName.length());
                        while (/*input.hasNext() &&*/ pm.read() != -1) {
                            setRecord(input.next());
                            dal.Connect();
                            String sql = "INSERT INTO fileinfo(pkey,id,date,time,mode)VALUES(%s,%s,%s,%s,'%s')";
                            sql = String.format(sql, i++, record.getId(), record.getDate(), record.getTime(), record.getMode());
                            dal.doCommand(sql);
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(null, e.getMessage() ," Read Record method.",JOptionPane.ERROR_MESSAGE);
                    dal.Disconnect();      
            }.start();
        public void closeFile() {
            input.close();
    }Edited by: firethumbs on Mar 26, 2009 12:43 PM

    IN THE NAME OF GOD
    hi firends
    i forget say one thing. if remove while loop content this program will work good. i suppose that the while condition and read file records not similar. because while condition check bytes but in while body read records. is that true?
    how can solve this problem?
    best regurds

  • How do I add a progress monitor to a drag and drop question in captivate 7

    I need to build a quiz. We have spent a lot of time on the style guide and appearance but I am having difficulty adding a progress monitor to my drag and drop questions. How can I do this?

    A Drag&Drop is not a normal question slide, hence that progress indicator is not added, and it wouldn't even be functional.
    Long time ago I explained how to create a custom progress indicator, maybe it can help you: Customized Progress Indicator - Captivate blog

  • Displaying progress monitor

    Hi there,
    I'm trying to display a progess monitor as a method runs. The problem is, I have no parent frame (I'm simply looking to display this progress monitor on screen by itself - like a JOptionPane message) However, I can't get anything to display:
    //...method code....
    ProgressMonitor progressMonitor = new ProgressMonitor(null,
                                      "Processing Array",
                                      "", 0, array.length);
           for (int i=0; i<array.length; i++){
           // do some processing on array
           progressMonitor.setProgress(i);
    progressMonitor.setProgress(array.length);
    // ...method continues...Am I trying to do the impossible?

    How to Use Progress Monitor:
    http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html
    Or, maybe the problem is the you need to be using threads:
    http://forum.java.sun.com/thread.jspa?messageID=3375278

  • Progress Monitor OR Progress Bar.........Please help

    I have a JFrame with a menu. As soon as I click the menu I am adding a panel to the JFrame which takes some time. To indicate this to the user should I use the Progress Bar or the progress monitor.
    In either case how do I use it?
    Thanks in advance and it would be very useful if someone could give a small skeleton code.
    Thanks once again

    I am having the same problem which you had with the progress bar.
    I have a DesktopPane with Menu Bar on the top and Internal Frames get added to the DesktoopPane according to the Menu Item selected and the Internal frame takes time to open I want to show the progress bar. I thing you have got the solution by this time.
    Has anybody else have the solution for the above. Basically i want to show the time taken by the classes to load a Internal frame using Progress Bar. Please send me the piece of code. Thanks in Advance.

  • Trouble connecting mbpro to dell monitor??

    i am conneting a macbook pro to a dell st2220l monitor with hmdmi to mini dvi cable. am having trouble getting full screen on the monitor??
    am sure this is an easy one so appreciate the help!!!

    Hi there,
    I would recommend taking a look at some of the troubleshooting steps found in the article below.
    Apple computers: Troubleshooting issues with video on internal or external displays
    http://support.apple.com/kb/ht1573
    Hopet that helps,
    Griff W.

  • Progress Monitoring

    Hi all,
    I need to set up a ProgressMonitor so to display the progress on the main task of my program. this is pretty complex and goes beyond my program, involving others tools. How can i monitorate it? In the example which i saw, in the tutorial and in the Swing Book, i just saw how to make it goes with a Timer, but it's far from an application task progress..!
    How can i deal with this?
    thank you,
    regards
    marco

    1. Destroying the old dialog box"old dialog box".dispose();
    3. creating the JProgressbar and making it
    indeterminateBetter create JProgressBar object before starting the thread.
    2. Starting the long task
    4. Destroying the JProgressBar
    5. informing the user that the task is completeIn your class, define the SwingWorker as:
        final SwingWorker worker = new SwingWorker() {
            public Object construct() {
                /* start your long task.
                 * Call local method, method from other
                 * class, whatever.
                return new Object();
            public void finished() {
                /* To finish off the long task.
                 * This method is called when the thread
                 * finishes.
                 * This where you destroy your progress bar
                 * and inform user the task is completed.
        };Of course, you'll need another thread to monitor the progress of your task, and increment the value in progress bar.
    As for indeterminate progress bar, you'll need to know some estimate anyway.
    If at all possible to break the long task in blocks/sections, that number can be applied to the progress bar. Otherwise, get an average performance time, and set the maximum with a figure, and slowly increment the progress bar. If it reaches 99% before finish, then I guess you have to wait till the task ends, then display 100%. If finishes quickly, then you can boost the speed of increment (or instantly display 100%).
    Alternatively, if you can determine (dynamically) how long before the end of task while running your task, you can always update your JProgressBar values (you probably aware of this, anyway).
    Hope this helps.

  • Progressive monitor export

    Saw this thread but didn't exactly answer my question.
    I'm exporting video shot in SD 60i to present on an HDTV (720p). What's the best export? I usually do the "DVD Best Quality 90 minute" with Mpegs and Dolby 2.0. Is there any fine tuning I need to do to make it look the best it can?
    Also, anyone know why broadcast SD content looks really good (detail/quality-wise) on HD sets, while the SD content I shoot looks the same as it does on my computer monitor? I've got a friend with an HD set at home and the local stations have HD channels on the cable network, and their SD stuff (shown on the HD channel) looks better than the regular SD channel. Is it because it's digital cable? Or is it that his set is a TV set (interlaced), not a computer monitor like my HDTV at work (720p)?
    Hope this makes sense.
    Thanks,
    Jonathan

    Just use log=<any filename> on the exp command line.
    The log file can be read by a different session.
    If you want to see progress (and cause a performance hit) use the feedback=
    option.
    You really would learn this a lot faster by reading the documentation instead of asking doc questions over and over again.
    Sybrand Bakker
    Senior Oracle DBA

  • Time effort to implement Business Process Monitoring

    hi,
    if one company want to utilize Business Process Monitoring and implement it:
    1). what are the Prerequisite
    2). if the Prerequisite are met and we come to BPMon part how long it would take to implement one Scenario.
    3). any document or links or hints for BPMon Best Practice?
    Regards

    Hi Volker,
    This comment was part of document - Business Process Monitoring Set-up and User Guideline for Release ST 4.0 and ST-SER 700_2007_1.
    3 Prerequisites for Business Process Monitoring
    Business Process Monitoring is not just activated by pressing a button in the SAP Solution Manager and
    therefore the configuration of Business Process Monitoring is currently not intended as a customer selfservice.
    Instead, the procedure to set up Business Process Monitoring in the SAP Solution Manager is rather
    realized by the delivery of the SAP Solution Management Optimization (SMO) Service for Business
    Process Management due to the complex nature of the overall configuration of Business Process Monitoring.
    However, it is possible (but not recommended) for customers to configure Business Process Monitoring by
    themselves without any guidance of SAP.
    Thanks.
    Mani

  • Progress monitoring for long operation

    I know that questions similar to this have been asked many times, but I have not gotten an answer that works for me, so here goes. I have a dialog box with various parameters that the user can specify for a long running task. After the user clicks "OK", I want the dialog box to disappear and instead to have an indeterminate jprogressbar display while the task is running. I have tried using SwingWorker classes and invokeLater(), but I ahve not gotten anything to work. Could someebody please help me out with which parts of the code:
    1. Destroying the old dialog box
    2. Starting the long task
    3. creating the JProgressbar and making it indeterminate
    4. Destroying the JProgressBar
    5. informing the user that the task is complete
    need to be performed using a SwingWorker or invokelater and how the parts should fit together.
    Thank you for the help,
    Jeff

    1. Destroying the old dialog box"old dialog box".dispose();
    3. creating the JProgressbar and making it
    indeterminateBetter create JProgressBar object before starting the thread.
    2. Starting the long task
    4. Destroying the JProgressBar
    5. informing the user that the task is completeIn your class, define the SwingWorker as:
        final SwingWorker worker = new SwingWorker() {
            public Object construct() {
                /* start your long task.
                 * Call local method, method from other
                 * class, whatever.
                return new Object();
            public void finished() {
                /* To finish off the long task.
                 * This method is called when the thread
                 * finishes.
                 * This where you destroy your progress bar
                 * and inform user the task is completed.
        };Of course, you'll need another thread to monitor the progress of your task, and increment the value in progress bar.
    As for indeterminate progress bar, you'll need to know some estimate anyway.
    If at all possible to break the long task in blocks/sections, that number can be applied to the progress bar. Otherwise, get an average performance time, and set the maximum with a figure, and slowly increment the progress bar. If it reaches 99% before finish, then I guess you have to wait till the task ends, then display 100%. If finishes quickly, then you can boost the speed of increment (or instantly display 100%).
    Alternatively, if you can determine (dynamically) how long before the end of task while running your task, you can always update your JProgressBar values (you probably aware of this, anyway).
    Hope this helps.

Maybe you are looking for

  • In PS CS6, Is there a way to break apart Handwritten text (not text recognition, just graphically)

    I have a scanned document that I want to eventually bring into After Effects to animate each handwritten letter so that it will form into an image... and because this is based on an artist's work, it needs to stay in her handwriting... So I want to p

  • Ipad3 will not open or shutoff

    I have been having problems of my iPad 3 in starting. It now shows the home screen with no number pad to open with my password. The "slide to unlock" is there and moves but will not slede open. I will not shut down with the power button and although

  • Creative cloud will not instal on Mac. Does nothing. Just sits there.

    Trying to download Creative cloud but it does nothing. I can see the installer and Creative Cloud on my Mac but nothing will open. It just hour glasses the installer. Makes it hard to download any product when step one wont work. Any feedback would b

  • Upgrade path

    we are upgrading from ACS 2.6 to 4.1 should we order the upgrade software (CSACS-4.1-WINUP-K9) or should we order the regular package (CSACS-4.1-WIN-K9)since 2.6 is so out of date?

  • Canvas children and mouseOver

    Simply put, I have a repeating canvas that contains buttons, an image, and a text field. When the user rolls their mouseOver the canvas, a child canvas becomes visible with buttons inside of it. Works great when you make sure that the mouse stays onl