繁体   English   中英

禁止在JFileChooser中重命名文件?

[英]Disable rename of a file in JFileChooser?

在JFileChooser中对文件单击两次(而不是双击)时,可以重命名所选文件。 如何禁用此功能? 我试过了

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

但它不起作用。

令人惊讶的是,您无法禁用重命名文件/从JFileChooser本身创建新目录。 正如您所推测的那样,您需要从UIManager中禁用此FileChooser“功能”。

这是一个可能有用的片段:

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”。

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

自定义JFileChooser外观和感觉有一些重命名常量

你的静态应该使用类进入JFileChooser

或者使用addMouseListener来点击。

暂无
暂无

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

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