简体   繁体   中英

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.

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.

有关从用于显示文件名的JList中删除MouseListener的手动解决方案,请参阅: https ://forums.oracle.com/forums/thread.jspa?messageID = 9933325&#9933325

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM