12

I'm developing a Java app using JavaFX for it's user interface.

When I use the FileChooser class to load a CSV file from the computer hard drive in Os X Mavericks the dialog shows me all the files and folders, even the hidden one creating a lot of noise and making really hard to find the desired file.

This screenshot illustrates what I'm talking about:

enter image description here

I think this could be more a OS X issue, but I don't understand how to fix, at least I don't understand how I can fix it with JavaFX FileChooser class.

Here's my code:

Stage stage = new Stage();
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open File");
fileChooser.getExtensionFilters().addAll(
        new FileChooser.ExtensionFilter("Comma-Separated Values (CSV)", "*.csv")
);
fileChooser.setInitialDirectory(
        new File(System.getProperty("user.home"))
);
File selectedFile = fileChooser.showOpenDialog(stage);

Update

This is the Google Chrome modal to open files.

enter image description here

4
  • 2
    Hi Dave, I think the problem is OS related. Have you tried to open a dialog from another app. Also you could try this. JFileChooser have a property to manage this behaviour setFileHidingEnabled but I can't find something similar for javafx, so probably it takes the OS behaviour. Regards
    – ELavicount
    Commented Apr 11, 2014 at 23:11
  • 2
    Hi @elavicount, I already checked the JFileChooser option and you are right, JavaFX seems it doesn't have a similar option. So I don't know, maybe is not posible in OS X because the filter works pretty well on Windows. Commented Apr 14, 2014 at 0:17
  • I advise asking the JavaFX developers on the open-jfx mailing list about this.
    – jewelsea
    Commented Jun 6, 2014 at 6:24
  • Today I ran into this problem myself. It appears it happens only on the first time that I open this dialog box after initializing the application, but it returns to normal every time after that. Perhaps maybe it's some sort of instantiation issue where the FileChooser class takes longer to properly load before the actual box opens. Commented Apr 10, 2016 at 19:15

3 Answers 3

1

After looking at sources... FileChooser is implemented over native dialogs and completely non customizable.

So, no, you can't force dialog to show/hide hidden files.

Inside FileChooser dialog there should be an context menu item to show/hide them, but you can't control this option from application

For example, here is how it looks on Linux:

FileChooser context menu

0

Have you tried hiding all hidden files in the Finder-program on the OS X machine? So: not using JavaFX, but using the program Finder?

3
  • I don't understand, why should I hide the files with finder? Maybe I don't get what you mean. Commented Jun 9, 2014 at 1:35
  • I'm assuming JavaFX launches some instance of Finder for you to select a file (which makes it look / feel the same as the actual Finder application), instead of having written their own. If this is actually the case (I'm not 100% sure), then your preferences of the Finder program (such as hiding files) will reflect the way the JavaFX file chooser behaves. Just trying to help Commented Jun 9, 2014 at 2:19
  • 1
    Oh I get it, but no, it doesn't work that way. Thank you tho. Commented Jun 9, 2014 at 4:54
0

I know this is late to the game but none of the answers really explain the situation for MacOS.

The open/save dialogs in JavaFX are native dialog (implemented as "sheets"). Just as Finder does not have a "show hidden files" option, these dialogs don't either. There are several solutions:

  1. Relatively unknown keyboard shortcuts, available since Mavericks: View Hidden Files in Mac Open and Save Dialog Boxes. (I just stumbled on this; I have always used #2 below.)

  2. Command-line switch in Terminal:

    • show hidden -> defaults write com.apple.finder AppleShowAllFiles YES, or
    • hide -> defaults write com.apple.finder AppleShowAllFiles NO

Your user has to be sufficiently aware of these alternatives; you cannot customize the native open/save dialog to provide a button to do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.