Maglioni Lorenzo Maglioni Lorenzo - 6 months ago 112
Java Question

Javafx filechooser name filter

i'd like to know if there's a way of filtering the names of files to make them selectable in the dialog to select files, for instance all files that starts for "A" and are in txt format, i searched a bit and i found only tips topics about the extension with the Extension filter, that's fine but i'd like to select just some file in a format.


In JavaFX you can filter for particular file types by adding ExtensionFilters to the list of filters returned by getExtensionFilters, like so:

FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().add(new ExtensionFilter("Text Files", "*.txt"));

The JavaFX file chooser does not support filtering by file name, only by extension. This is because most platforms don't support this functionality natively in their file choosers.