Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 471
Maglioni Lorenzo Avatar asked Oct 17 '25 06:10

Maglioni Lorenzo


1 Answers

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.

like image 61
Joseph Earl Avatar answered Oct 19 '25 22:10

Joseph Earl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!