• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

Process JDialog

Does anyone have a quick class to produce a JDialog saying processing or something along that lines, to be displayed and automatically disposed of while a procedure is processing... leave the main JFrame process anyway while the JDialog is being displayed and then be automatically disposed of.
0
dwaneos
Asked:
dwaneos
  • 3
  • 2
  • 2
2 Solutions
 
objectsCommented:
Have a look at ProgressMonitor class.
0
 
objectsCommented:
If you want to build it yourself then the SwingWorker class makes it fairly straightforward.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
dwaneosAuthor Commented:
I don't get it... how does the progessMonitor know when to dispose of itself when the process has stopped.
0
 
TimYatesCommented:
Does this help:

http://mail.phys-iasi.ro/Library/Computing/jfc_unleashed/ch21.htm

---------------

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * An application that displays a ProgressMonitor
 * when the 'start' button is pressed. A simple
 * 'operation' to update the monitor
 *
 * @author Mike Foley
 **/

public class ProgressTest extends Object {

    /**
     * Application entry point.
     * Create the splash window, and display it.
     *
     * @param args Command line parameter. Not used.
     **/
    public static void main( String args[] ) {

        //
        // Create a frame with a single button in it.
        // When the button is pressed, a thread is spawned
        // to run out sample operation.
        //
        JFrame frame = new JFrame( "ProgressMonitor Test" );
        JButton button = new JButton( "Start" );
        frame.getContentPane().add( button, BorderLayout.CENTER );

        //
        // Create a ProgressMonitor. This will be started
        // when the button is pressed.
        //
        int min = 0;
        int max = 100;
        String[] message = new String[2];
        message[0] = "Performing Operation.";
        message[1] = "This may take some time...";
        final ProgressMonitor monitor = new  ProgressMonitor( frame,
                                                      message,
                                                      "Iteration",
                                                      min,
                                                      max );

        //
        // This is our sample operation.
        //
        final Runnable runnable = new Runnable() {
            public void run() {
                int sleepTime = 500;
                for( int i = 1; i < 100; i++ ) {
                    try {                        
                        monitor.setNote( "Iteration " + i );
                        monitor.setProgress( i );
                        if( monitor.isCancelled() ) {
                            monitor.setProgress( 100 );
                            break;
                        }
                        Thread.sleep( sleepTime );
                    }  catch( InterruptedException dontcare ) {                    
                    }
                }
                monitor.close();
            }
        } ;
       
        button.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent event ) {
                //
                // Run the operation in its own thread.
                //
                Thread thread = new Thread( runnable );
                thread.start();

            }
        }  );
       
        //
        // Show the frame.
        //
        frame.pack();
        frame.setVisible( true );

    }  // main

}  // ProgressTest
0
 
dwaneosAuthor Commented:
What about the isCancelled()?
Where does that fit in to all of it?
0
 
TimYatesCommented:
There is a "Cancel" button on the progressMonitor dialog...

if the user presses it, isCancelled() returns true...
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now