Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7144499

JOptionPane is not modal for JInternalFrames

    Details

      Description

      FULL PRODUCT VERSION :
      Compile with java 6 or Java 7

      Run with jre7

      C:\Users\dr>java -version
      java version "1.7.0_02"
      Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
      Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7, 32 bit. Have not tested other versions.

      A DESCRIPTION OF THE PROBLEM :
      Modal behavior of JOptionPane has changed from jre6 to jre7.

      Under all versions before jre7 it was possible to display a message using JOptionPane in serial fashion on the EventQueue and it would interrupt the EventQueue and display a modal message. That message would receive focus..

      Now the message is no longer modal. It displays correctly but it does not receive focus. Instead, the focus remains with the underlying JInternalFrame.

      This behavior occurs when running under JRE7 regardless of whether the class was complied with JDK6 or JDK7. It does not occur under JRE6.

      JOptionPane is not thread safe, but when run on the EventQueue it should work correctly because, in the past, JOptionPane temporarily replaced the EventQueue.

      This focus/modal behavior did not occur in any previous version. Previous versions blocked the EventQueue and the JOptionPane received focus and worked as expected until it was closed.

      The problem also occurs regardless of the setting for dialog.setModalityType in JOptionPane. And it appears to only affect underlying JInternalFrames.

      REGRESSION. Last worked in version 6u29

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Put this in a JInternalFrame:

      String actionName
      int sunMap = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;

      // Escape
      actionName = "CloseWindow";
      Action closeWindowAction = new AbstractAction() {
           public void actionPerformed(ActionEvent ev) {
                  doDefaultCloseAction();
            }
      };
      windowPanel.getInputMap(sunMap).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), actionName);
      windowPanel.getActionMap().put(actionName, closeWindowAction);

      Display the JInternalFrame. Add a button that displays a JOptionPane, display a message using JOptionPane and press Escape. The JInternal Frame will close instead of the JOptionPane.

      This nonmodal behavior does not affect JFrames. It only affects JInternalFrames.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      If a modal message is displayed on the EventQueue it should receive focus and be modal.
      ACTUAL -
      The message displays but does not receive focus

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      See steps to reproduce
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Call using EventQueue.invokeLater.

      However, this breaks over a decade of existing code.

      It is also possible to disable focusable components on the underlying JInternalFrame before calling JOptionPane. This causes the focus to move to the JOptionPane.

      However, this introduces a lot of extra code to overcome the absence of modal behavior.

        Attachments

          Activity

            People

            • Assignee:
              rupashka Pavel Porvatov (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: