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

Regress: OracleFileChooserUI is no longer calling FileChooser.setSelectedFile

XMLWordPrintable

       

      I have a filechooser in a JDialog. When I open the filechooser and type the file name (which exists in the directory shown in the filechooser) in the
      file name textfield and press "ENTER" key, the filechooser.setSelectedFile() method is not getting called and the file is not selected in the filechooser ui.

      Here is the testcase code:

      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import java.io.File;

      import javax.swing.JButton;
      import javax.swing.JDialog;
      import javax.swing.JFileChooser;

      import javax.swing.JFrame;

      import javax.swing.JPanel;
      import javax.swing.UIManager;

      import oracle.bali.ewt.dialog.JEWTDialog;

      public class FileChooserDemo extends JPanel
      {
        public FileChooserDemo()
        {
          super();
          JButton b = new JButton("Test");
          add(b);
          b.addActionListener(new ActionListener()
                              {
                                public void actionPerformed(ActionEvent ae)
                                {
                                  _runFileChooser(true,
      JFileChooser.FILES_AND_DIRECTORIES, true);
                                }
                              });
        }
         
        private void _runFileChooser(boolean open, int mode, boolean multi)
        {
            JFileChooser chooser = new JFileChooser()
            {
              public void setSelectedFile(File file)
              {
                System.out.println(file);
                Thread.dumpStack();
                super.setSelectedFile(file);
              }
            };
            chooser.setMultiSelectionEnabled(multi);
            chooser.setFileSelectionMode(mode);
             
            File f = new File("C:\\Temp\\Softwares");
            chooser.setCurrentDirectory(f);
             
            JDialog d = new JDialog();
            d.add(chooser);
            d.pack();
            d.setVisible(true);

      // int retval = (open) ? chooser.showOpenDialog(this) :
      // chooser.showSaveDialog(this);

             
          }
         
        public static void main(String[] args)
        {
          try
          {
            //UIManager.setLookAndFeel("oracle.bali.ewt.olaf2.OracleLookAndFeel");
          }
          catch(Exception e)
          {
             
          }
          JFrame fr = new JFrame("File ChooserDemo");
          fr.add(new FileChooserDemo());
          fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          fr.pack();
          fr.setVisible(true);
        }
      }


      Steps:
      1. Run the testcase:
      2. Click on "Test" button
      3. A JDialog will come up with the FileChooser.
      4. Type any file names (full name with extension) thats present in the
      directory (if not change to a directory and type any file present in the dir
      inside the textField)
      5.Press ENTER key. Look at the console. There is no Thread stack trace or any

      printouts. Also the file is not selected (blue highlight) in the file chooser

      dialog.

      This used to work in JDK 1.6.0_31. Not working in JDK 1.7.0

      The issue in MetalLookAndFeel:
      In 1.6:
          "FileChooser.ancestorInputMap",
             new UIDefaults.LazyInputMap(new Object[] {
           "ESCAPE", "cancelSelection",
           "F2", "editFileName",
           "F5", "refresh",
           "BACK_SPACE", "Go Up",
           "ENTER", "approveSelection",
      "ctrl ENTER", "approveSelection"
      }),

      But in 1.7:
                  "FileChooser.ancestorInputMap",
                     new UIDefaults.LazyInputMap(new Object[] {
                           "ESCAPE", "cancelSelection",
                           "F2", "editFileName",
                           "F5", "refresh",
                           "BACK_SPACE", "Go Up"
                       }),

      Note that the "approveSelection" action key is removed and hence this bug is
      getting reproduced.

      Because of this some of our tests are failing (look at base bug). Would be
      great if this gets addressed soon. Thanks.
       
       

            aivanov Alexey Ivanov
            asaha Abhijit Saha
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: