I have a JFileChooser
that opens in a specific directory and then allows the user to choose a directory within it (when selected w/ single-click and the OK
button is pressed).
However, when the directory is double-clicked, the file chooser opens that directory instead of choosing it.
How can I either
- override the double-click to choose the directory
- disable navigation outside of the initial directory
- disable double-clicking?
I've tried overriding the isTraversable()
method in FileView
and FileSystemView
which works to restrict the file chooser to a directory, however, it then does not show any items inside of said directory.
Here's the code I have right now:
JFileChooser fc = new JFileChooser(dir);
fc.setApproveButtonText("OK");
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.showOpenDialog(fileChooserDialog);
File file = fc.getSelectedFile();
if (file.getParent().equals(dir)) {
//do something
}