Class ProgressDialog<T>

All Implemented Interfaces:
ComponentListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants, ProgressComponent.Listener<T>

public class ProgressDialog<T> extends JDialog implements ComponentListener, ProgressComponent.Listener<T>
See Also:
  • Field Details

    • NOT_CANCELABLE

      public static final ProgressDialog.Option NOT_CANCELABLE
      Option to pass to make the Cancel button inactive, forcing the user to wait until the task is completed.
    • NO_FOCUS_STEALING

      public static final ProgressDialog.Option NO_FOCUS_STEALING
      Option to pass to prevent the popup that opens while the task is running to display its progress, from stealing the keyboard focus.
  • Constructor Details

  • Method Details

    • setVisible

      public void setVisible(boolean b)
      When invoked with true, displays the dialog and starts the configured ProgressTask in a background thread, then blocks until the task has completed and the dialog is disposed of. Events are dispatched while this method is blocked.
      Overrides:
      setVisible in class Dialog
      Parameters:
      b - true to show the dialog and start the task in a background thread.
    • executeTask

      public static <T> T executeTask(Window parent, ProgressTask<T> task, ProgressDialog.Option... options)
      Execute a task in the background with progress reporting via a modal dialog with a progress bar. The task is executed on a separate thread. This method blocks until the task has completed, but events are dispatched while the method is blocked. If the task throws an exception, that exception will be rethrown by this method.

      By default the Cancel button is enabled and the popup will steal the keyboard focus. Use one or more of the NOT_CANCELABLE and NO_FOCUS_STEALING options to modify this.

      Type Parameters:
      T - The return type of the task. Use Void for tasks which don't return a value.
      Parameters:
      parent - The parent window for the modal dialog.
      task - The task to execute.
      options - Optional modifiers to change the behaviour. See NOT_CANCELABLE and NO_FOCUS_STEALING.
      Returns:
      The result of the task, or null if the task does not return a result or if it was cancelled.
      Throws:
      Error - If the task threw an Error.
      RuntimeException - If the task threw a RuntimeException.
    • executeTask

      public static <T> T executeTask(Window parent, String name, Callable<T> task, ProgressDialog.Option... options)
      Execute a task in the background with progress reporting via a modal dialog with a progress bar. The task is executed on a separate thread. This method blocks until the task has completed, but events are dispatched while the method is blocked. If the task throws an exception, that exception will be rethrown by this method.

      By default the Cancel button is enabled and the popup will steal the keyboard focus. Use one or more of the NOT_CANCELABLE and NO_FOCUS_STEALING options to modify this.

      Type Parameters:
      T - The return type of the task. Use Void for tasks which don't return a value.
      Parameters:
      parent - The parent window for the modal dialog.
      name - The name of the task to execute. Will be displayed to the user.
      task - The task to execute.
      options - Optional modifiers to change the behaviour. See NOT_CANCELABLE and NO_FOCUS_STEALING.
      Returns:
      The result of the task, or null if the task does not return a result or if it was cancelled.
      Throws:
      Error - If the task threw an Error.
      RuntimeException - If the task threw a RuntimeException.
    • componentShown

      public void componentShown(ComponentEvent e)
      Specified by:
      componentShown in interface ComponentListener
    • componentResized

      public void componentResized(ComponentEvent e)
      Specified by:
      componentResized in interface ComponentListener
    • componentMoved

      public void componentMoved(ComponentEvent e)
      Specified by:
      componentMoved in interface ComponentListener
    • componentHidden

      public void componentHidden(ComponentEvent e)
      Specified by:
      componentHidden in interface ComponentListener
    • exceptionThrown

      public void exceptionThrown(Throwable exception)
      Specified by:
      exceptionThrown in interface ProgressComponent.Listener<T>
    • done

      public void done(T result)
      Specified by:
      done in interface ProgressComponent.Listener<T>
    • cancelled

      public void cancelled()
      Specified by:
      cancelled in interface ProgressComponent.Listener<T>