When you click twice (not double click) on a file in JFileChooser, you can rename the selected file. How to disable this feature? I've tried with
UIManager.put("FileChooser.readOnly", Boolean.TRUE);
but it doesn't work.
Surprisingly, you cannot disable renaming files/creating new directories from JFileChooser itself. As you correctly surmised, you need to disable this FileChooser "feature" from UIManager instead.
Here's a snippet that might help:
http://www.coderanch.com/t/555535/GUI/java/FileChooser-readOnly
Boolean old = UIManager.getBoolean("FileChooser.readOnly");
UIManager.put("FileChooser.readOnly", Boolean.TRUE);
JFileChooser fc = new JFileChooser(".");
UIManager.put("FileChooser.readOnly", old);
The key thing is to set "FileChooser.readOnly" BEFORE you create the file chooser.
Customizing a JFileChooser Look and Feel has some rename constants
Your static should go into the JFileChooser
using class.
Alternatively do addMouseListener
to throw click away.
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