简体   繁体   English

禁止在JFileChooser中重命名文件?

[英]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. 在JFileChooser中对文件单击两次(而不是双击)时,可以重命名所选文件。 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. 令人惊讶的是,您无法禁用重命名文件/从JFileChooser本身创建新目录。 As you correctly surmised, you need to disable this FileChooser "feature" from UIManager instead. 正如您所推测的那样,您需要从UIManager中禁用此FileChooser“功能”。

Here's a snippet that might help: 这是一个可能有用的片段:

http://www.coderanch.com/t/555535/GUI/java/FileChooser-readOnly 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. 关键是在创建文件选择器之前设置“FileChooser.readOnly”。

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

Customizing a JFileChooser Look and Feel has some rename constants 自定义JFileChooser外观和感觉有一些重命名常量

Your static should go into the JFileChooser using class. 你的静态应该使用类进入JFileChooser

Alternatively do addMouseListener to throw click away. 或者使用addMouseListener来点击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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