I'm using Directory Chooser for set a TextField with the selected path. If I choose some directory like Desktop, or any other folder it returns the path, BUT if I choose the directorys from my library like my Documents (C:\Users\Victor\Documents) it returns null. Is it a bug?? I'm using the code below:
DirectoryChooser chooser = new DirectoryChooser();
chooser.setTitle("Selecione o diretório");
File defaultDirectory = new File(folderChooser);
chooser.setInitialDirectory(defaultDirectory);
File selectedDirectory = chooser.showDialog(null);
pathFolderTxtField.setText(selectedDirectory.getAbsolutePath());
folderChooser = selectedDirectory.getPath();
This is a bug.
It is fixed in JavaFX 2.2.6 and Java 8 (both not yet released):
RT-28571 Choose a Windows 7 Library in a DirectoryChooser results in a COM Error
The fix doesn't actually allow library selection. If the user tries to select a library, instead the JavaFX system pops up an alert and prevents the directory chooser from closing:
Sample code I ran on JavaFX 2.2.4 (which gave an error) and the early access Java 8b77 (which showed the alert message instead) was:
Error reported is:
To get the error you need to choose a library from the left hand panel of the directory chooser dialog.