kofucii
kofucii

Reputation: 7653

Disable rename of a file in JFileChooser?

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.

Upvotes: 4

Views: 6185

Answers (2)

Joop Eggen
Joop Eggen

Reputation: 109577

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.

Upvotes: 1

paulsm4
paulsm4

Reputation: 121719

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.

Upvotes: 11

Related Questions