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

Enter key does not work in a deserialized JFileChooser

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b116
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When showing an open or save dialog for a JFileChooser instance that has been read from an ObjectInputStream, the enter key does nothing in the resulting dialog. It works as expected before serialization.

      REGRESSION. Last worked in version 7u75

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Instantiate a JFileChooser.
      Serialize the JFileChooser instance using an ObjectOutputStream.
      Deserialize the JFileChooser instance using an ObjectInputStream.
      Show an open or save dialog for the deserialized JFileChooser instance.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The Open/Save button should be the default button for the enter key. Showing the original JFileChooser produces the expected result. The enter key should do the same as it did before serialization/deserialization steps.
      ACTUAL -
      When showing the deserialized JFileChooser, the enter key does nothing.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      JFileChooser jfc = new JFileChooser();
      //jfc.showOpenDialog(null);
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(bos);
      oos.writeObject(jfc);
      oos.close();
      ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bis);
      JFileChooser deserialized = (JFileChooser) ois.readObject();
      deserialized.showOpenDialog(null);
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Executing the following piece of code immediately after deserializing appears to solve the problem.

      KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
      InputMap map = deserialized.getInputMap( JFileChooser.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
      map.put(enter, "approveSelection");

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ssadetsky Semyon Sadetsky (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: