Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable hidden files using FileChooser from JavaFX

Tags:

java

macos

javafx

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

like image 466
David Gomez Avatar asked Apr 11 '14 17:04

David Gomez


1 Answers

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

like image 71
acc15 Avatar answered Oct 08 '22 04:10

acc15