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:
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.
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:
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?
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:
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.)
Command-line switch in Terminal:
defaults write com.apple.finder AppleShowAllFiles YES
, or 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.