Forums Register Login

Can JFileChooser display files, but only allow directory selection?

+Pie Number of slices to send: Send
I have a JFileChooser in which a user needs to select a save-to directory (to which to save a batch of files). After using it, a few people have commented that it would be good to allow users to actually see the files that exist in the directory, before they choose that directory (which makes sense, IMHO). But again, the user shouldn't be allowed to actually select a file.

Problem is, JFileChooser seems to tightly couple what a user can see and what they can select. I've been playing around with a few kludges without anything I results that I consider satisfactory. For example, set the file selection mode to FILES_AND_DIRECTORIES, and if the user selects a file, then behind-the-scenes just use that file's parent. But that's non-intuitive and misleading from a UI perspective. Or, use FILES_AND_DIRECTORIES mode but if the user selects a file, then set the current selection to that file's parent... but that causes the UI to jump around.

So, is there something basic I am missing? Or has anyone ever successfully tackled that problem?
+Pie Number of slices to send: Send
As I read the docs, "setFileFilter(FileFilter)" allows you to "filter out files from the user's view", i.e. to control what the user sees, and "setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)" allows the user to "just select directories".

It's possible that the documentation is badly worded here. But if it's correct then you can do what you want. I haven't tried it.
He's giving us the slip! Quick! Grab this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2017 times.
Similar Threads
Problem with JFileChooser
directory structure
NX: DB File Location in suncertify.properties
JFileChooser options
About data file in server case!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:38:21.