[访问 文件类型图标Mac OSX

问题描述 投票:2回答:3

我正在尝试找到一种访问Mac OSX系统图标的方法。有人知道他们在Mac上的默认位置吗?还是知道使用Java来返回它们的方法?

[有一种使用Mac的JFileChooser检索文件图标的方法,但是该文件必须存在于文件系统上(在我的应用程序中,该文件可能是从服务器流式传输的,因此无需在服务器上创建虚拟文件。具有该扩展名的系统将无法正常工作)。

我可以通过以下方式使用SWT在Windows上访问它们(但是在Mac上是炸弹)。下面的变量“ fileType”例如是“ .txt”,“。bmp”,“。doc”等:

Program p;
Image image;

//find the correct OS image for the file type and set
//the image to the tree item
p = Program.findProgram(fileType);
ImageData data = p.getImageData();
image = new Image(display, data);

更新:似乎没有一个清晰的方法来导入它们。我最终在网上找到了一些通用的Mac图标,并将它们与我的应用程序捆绑在一起,以便在Mac上仅使用getRecourceAsStream(),直到找到更好的解决方案为止。

java macos system icons
3个回答
3
投票

已经晚了,但也许其他人会搜索相同的问题(例如我)。

FileSystemView技巧仅适用于所有平台上的16x16图像。在Mac上,您需要使用默认的Aqua外观才能使其正常工作。

对于Windows,您可以使用ShellFolder.getShellFolder(file).getIcon(true)来获得32x32图标。

对于Mac,您可以使用一些Objective-C jni库附带的Quaqua,这些库为您提供了任何文件(16px,32、64、128、256、512)的所需/可用图标大小:http://www.randelshofer.ch/quaqua/javadoc/ch/randelshofer/quaqua/osx/OSXFile.html#getIcon%28java.io.File,%20int%29


2
投票

在OS X上,FileViewFileSystemView更好。我正在使用以下方法获取文件图标:

final JFileChooser fc = new JFileChooser();
//return fc.getFileView().getIcon(f); // will throw a  null pointer
Icon result = fc.getUI().getFileView(fc).getIcon(f);

0
投票

我认为FileSystemView及其朋友提供了获取文件图标的方法。

© www.soinside.com 2019 - 2024. All rights reserved.