开发者

How to get the linux folder and file icons and names in java? [duplicate]

This question already has answers here: How do you get the icon, MIME type, and application associated with a file in the Linux Desktop? (9 answers) Closed 2 years ago.

I'm creating a tree of folders and files in java. Windows and OSX return the system icons and name开发者_StackOverflow with the following code:

new JFileChooser().getIcon(File f);
new JFileChooser().getName(File f);

Is there any possibility to get the icons and name of unix systems?. A system command would be ok too.

Thanks.


I did not tested but this code should work on most systems:

FileSystemView view = FileSystemView.getFileSystemView();
Icon icon = view.getSystemIcon(file);


You can always get the name of the system you are working on, Java allows you to do a native execution and capture the results of this (command line, so for unix flavors, Runtime.exec("uname -a");) then parse the results in the output stream.

Having said that, there are a number of different implementations of GUI layers on top of a unix kernel, and there is not a standard way of retrieving the mappings between file types and icon images. You can make a solution specific to a window manager, but would need to change your algorithm based on which wm is being used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜