Pregunta

I have created a small application in javafx wherein one has to choose JPG,PNG or GIF image to work with. Here's the code am using to filter the files :

FileChooserBuilder fcb = FileChooserBuilder.create();
FileChooser fc = fcb.title("Open Dialog").initialDirectory(new File(currentDir)).build();

//Set extension filter
FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
FileChooser.ExtensionFilter extFilterGIF = new FileChooser.ExtensionFilter("GIF files (*.gif)", "*.GIF");

fc.getExtensionFilters().addAll(extFilterJPG, extFilterPNG, extFilterGIF);

selectedFile = fc.showOpenDialog(link);

This code works fine in Windows 7. But while using it in Ubuntu it doesn't show me all files with JPG, PNG or GIF. It shows a few, but I couldn't exactly make out why it does that.

¿Fue útil?

Solución

Ubuntu and unix like systems are case sensitive. So it's filtering for "*.JPG" and maybe you have files with uppercase or lowercase extension. So the file won't match in the case of files with lowercase extension.

In windows, there is no problem, because it isn't case sensitive, I mean, one.jpg it's the same that one.JPG.

So to fix it add the extension in lowercase in the constructor of the ExtensionFilter.

FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG", "*.jpg");

Hope it helps

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top