JDK-8065861 : Pressing Esc does not set 'canceled' property of ProgressMonitor
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8,8u25,9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-11-04
  • Updated: 2022-10-28
  • Resolved: 2016-06-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b127Fixed
Related Reports
Duplicate :  
Sub Tasks
JDK-8164429 :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux fox 2.6.32-5-amd64 #1 SMP Tue May 13 16:34:35 UTC 2014 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
The isCanceled() method of ProgressMonitor returns false if the use presses Esc while the ProgressMonitor's dialog has keyboard focus.  The dialog closes, but isCanceled() continues to return false.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Display a ProgressMonitor dialog.  Before it reaches its maximum progress value, press Esc to close it (as opposed to activating the Cancel button or closing the dialog via the window manager).  Observe the value returned by the ProgressMonitor's isCanceled() method.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Pressing Esc should perform exactly the same action as activating the dialog's Cancel button.  The isCanceled() method of the ProgressMonitor should return true.
ACTUAL -
When the ProgressMonitor's dialog is closed by pressing Esc, the isCanceled() method continues to return false.  Closing the ProgressMonitor's dialog by any other means correctly causes isCanceled() to return true.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.ProgressMonitor;

public class ProgressMonitorTest {
    static ProgressMonitor monitor;
    static int p;

    public static void main(String[] args)
    throws InterruptedException,
           ReflectiveOperationException {

        EventQueue.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                JFrame frame = new JFrame("Test");
                frame.setSize(300, 300);
                frame.setLocationByPlatform(true);
                frame.setVisible(true);

                monitor = new ProgressMonitor(frame, "Progress", null, 0, 100);
            }
        });

        for (p = 10; p <= 100; p += 10) {
            Thread.sleep(1000);
            EventQueue.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    if (!monitor.isCanceled()) {
                        monitor.setProgress(p);
                    }
                }
            });
        }

        EventQueue.invokeAndWait(
            () -> System.out.println("Canceled=" + monitor.isCanceled()));

        System.exit(0);
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Create your own dialog (possibly a JOptionPane) and put a JProgressBar in it.


Comments
URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/242fbca3aa3c User: amurillo Date: 2016-07-13 03:50:56 +0000
13-07-2016

URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/242fbca3aa3c User: psadhukhan Date: 2016-06-28 10:47:24 +0000
28-06-2016

Text for release-note : ------------------------------- The ProgressMonitor dialog can be closed in following ways : 1. 'Cancel' button is pressed 2. Dialog Close button is pressed 3. Escape key is pressed If the PrgressMonitor dialog is closed, ProgressMonitor.isCanceled() method used to return 'true' in only cases (1) and (2) above. This fix corrects the behavior where ProgressMonitor.isCanceled() method will return 'true' in case the ProgressMonitor dialog is closed by pressing Escape key. There is low compatibility impact of this fix : This change may impact user code that (incorrectly) assumes ProgressMonitor.isCanceled() will return false even if the ProgressMonitor dialog is closed as a result of pressing Escape key. Also, with this change, now there is no way to get the ProgressMonitor dialog out of way whilst having progress continue.
28-06-2016

This issue is reproducible with JDK 8, 8u20, and 8u25. Failed to compile with JDK 7u72, 8u40, and 9ea with following error: ProgressMonitorTest.java:39: error: illegal start of expression () -> System.out.println("Canceled=" + monitor.isCanceled())); ^ ProgressMonitorTest.java:39: error: illegal start of expression () -> System.out.println("Canceled=" + monitor.isCanceled())); ^ 2 errors
25-11-2014