Disable file rename in JFileChooser?

When you double-click (not double-click) a file in JFileChooser, you can rename the selected file. How to disable this feature? I tried using

UIManager.put("FileChooser.readOnly", Boolean.TRUE);

but that will not work.

+5
source share
3 answers

For a guide on removing MouseListener from the JList used to display file names, see: https://forums.oracle.com/forums/thread.jspa?messageID=9933325鈍

+2
source

Surprisingly, you cannot turn off file renaming / creating new directories from JFileChooser itself. As you correctly understood, you need to disconnect this "FileChooser" function from UIManager.

, :

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);  

, "FileChooser.readOnly" .

+11

JFileChooser Look and Feel setting has some renaming constants

Your statics should go into the class JFileChooserusing the class.

Alternatively, make addMouseListenerto click.

+1
source

All Articles