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

Mac: Open FileChooser will select a directory if its name matches the Extension Filter glob list.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u20
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:
    • Environment:

      Java 8u20 b10 OS X 10.9

      Description

      I have a one document file type for my application that has a the extension .fid. Sometimes these files will be found inside a directory which has the same extension (eg Sample1.fid/1.fid).

      With the OSX FileChooser in JavaFX I have just noticed that putting "*.fid" in the list of extensions in an ExtensionFilter will cause the chooser to not allow the user to descend into that folder. Instead it will "open" the folder as if it's a file. Shouldn't this behavior be saved for using a directory chooser?

      To observe this issue, please follow these steps:

      1. Create a folder called "testFolder.fid" and create an empty file in that folder called "testFile.fid". Also create another empty file called testFile.fid next to the folder you just created.

      2. Run the provided test class and click on the Open... button.

      3. Navigate with the file chooser to the testFolder.fid folder. Notice that you cannot look inside the folder with this file chooser. If you click on Open it will return the folder as the file chosen.

      4. Next try to open the testFile.fid file next to the folder. It will open as expected.


      ******************************************* Test Class ***********************************************
      import java.io.File;

      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.StackPane;
      import javafx.stage.FileChooser;
      import javafx.stage.FileChooser.ExtensionFilter;
      import javafx.stage.Stage;

      public class FileChooserTest extends Application {

         @Override public void start(Stage primaryStage) throws Exception {
            
            primaryStage.centerOnScreen();
            primaryStage.setHeight(350);
            primaryStage.setWidth(500);
            
            Button button = new Button("Open...");
            button.setOnAction( new EventHandler<ActionEvent>() {
               @Override public void handle(ActionEvent event) {
                  FileChooser chooser = new FileChooser();
                  chooser.getExtensionFilters().add(
                        new ExtensionFilter("My File Type", "*.fid") );
                  File f = chooser.showOpenDialog(primaryStage);
                  if ( f != null ) {
                     System.out.println( (f.isDirectory() ? "Directory chosen: " :
                        "Fle chosen: ") + f );
                  } else {
                     System.out.println("File chooser cancelled.");
                  }
                  
               }
            });
            
            primaryStage.setScene(new Scene( new StackPane( button ) ) );
            primaryStage.show();
         }

         public static void main(String[] args) throws Exception {
            launch(args);
         }

      }

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            csmithjfx Charles Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Imported: