JFileChooser 内部的所有控件

本文介绍如何通过修改UIManager属性来实现JFileChooser组件的国际化,包括标题、按钮文本及图标等的自定义设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在网上找了很多例子,都不是很全面的介绍应该怎么去更改jFileChooser国际化的方法,下文是对网上搜集的资料进行收藏

   JFileChooser chooser=new JFileChooser("Open");

//sets the text and language of all the components in JFileChooser
//这些在中英切换当中可以用到
        UIManager.put("FileChooser.openDialogTitleText", "Open");
        UIManager.put("FileChooser.lookInLabelText", "LookIn");
        UIManager.put("FileChooser.openButtonText", "Open");
        UIManager.put("FileChooser.cancelButtonText", "Cancel");
        UIManager.put("FileChooser.fileNameLabelText", "FileName");
        UIManager.put("FileChooser.filesOfTypeLabelText", "TypeFiles");
        UIManager.put("FileChooser.openButtonToolTipText", "OpenSelectedFile");
        UIManager.put("FileChooser.cancelButtonToolTipText","Cancel");
        UIManager.put("FileChooser.fileNameHeaderText","FileName");
        UIManager.put("FileChooser.upFolderToolTipText", "UpOneLevel");
        UIManager.put("FileChooser.homeFolderToolTipText","Desktop");
        UIManager.put("FileChooser.newFolderToolTipText","CreateNewFolder");
        UIManager.put("FileChooser.listViewButtonToolTipText","List");
        UIManager.put("FileChooser.newFolderButtonText","CreateNewFolder");
        UIManager.put("FileChooser.renameFileButtonText", "RenameFile");
        UIManager.put("FileChooser.deleteFileButtonText", "DeleteFile");
        UIManager.put("FileChooser.filterLabelText", "TypeFiles");
        UIManager.put("FileChooser.detailsViewButtonToolTipText", "Details");
        UIManager.put("FileChooser.fileSizeHeaderText","Size");
        UIManager.put("FileChooser.fileDateHeaderText", "DateModified");
        SwingUtilities.updateComponentTreeUI(chooser);
 
 
 
//下面这些是图标的可用和不可用,可以设置成不可用状态或是换图标
public class FileSystem extends JFileChooser{
  
    public FileSystem(String title){
        super(title);
          
        //icons for the JFileChooser
        UIManager.put("FileView.directoryIcon", new ImageIcon(FileSystem.class.getResource("folder.png")));
        UIManager.put("FileChooser.homeFolderIcon", new ImageIcon(FileSystem.class.getResource("user-home.png")));
        UIManager.put("FileView.computerIcon", new ImageIcon(FileSystem.class.getResource("computer.png")));
        UIManager.put("FIleView.floppyDriveIcon", new ImageIcon(FileSystem.class.getResource("media-floppy.png")));
        UIManager.put("FileView.hardDriveIcon", new ImageIcon(FileSystem.class.getResource("drive-harddisk.png")));
        UIManager.put("FileView.fileIcon", new ImageIcon(FileSystem.class.getResource("file.png")));
        UIManager.put("FileChooser.upFolderIcon", new ImageIcon(FileSystem.class.getResource("go.png")));
        UIManager.put("FileChooser.newFolderIcon", new ImageIcon(FileSystem.class.getResource("folder-new.png")));
        UIManager.put("FileView.fileIcon", new ImageIcon(FileSystem.class.getResource("file.png")));
        UIManager.put("FileChooser.listViewIcon", new ImageIcon(FileSystem.class.getResource("listIcon.png")));
        UIManager.put("FileChooser.detailsViewIcon", new ImageIcon(FileSystem.class.getResource("details.png")));
        SwingUtilities.updateComponentTreeUI(this);
          
    }
  
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值