I have created a JFileChooser and I want to restrict it only in the user.home dir and it's subfolders.
The selection mode of my JFileChooser is directories only.
So far I have used this:
//JButton select = new JButton();
final File directorylock = new File(System.getProperty("user.home"));
JFileChooser browse = new JFileChooser(directorylock);
browse.setFileView(new FileView() {
@Override
public Boolean isTraversable(File f) {
return directorylock.equals(f);
}
});
But every time I open the JFileChooser it only shows me the user.home directory without it's subfolders and therefore I cannot access them or select them.
How it should work: Open JFileChooser and show the user.home directory with all it's subfolders. Be able to access the subfolders and select them. NOT be able to access parent folders. of the user.home directory.
I hope someone here knows how this is supposed to be done! :) Thank you guys in advance :D
Check out the Single Root File Chooser.
You will only ever see the single file you specify in the combo box so you don't confuse the user that you can select a parent directory.
Then You will only be able to select a file in the directory or sub directory of the file you specify when creating the class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With