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

2

6

I'm creating a tree of folders and files in java. Windows and OSX return the system icons and name 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.

Reunion answered 15/6, 2010 at 7:49 Comment(2)
Problem: I suspect it would depend on the environment - is it Gnome? KDE? XFCE? Another, less widespread environment? Because of that, a cross-desktop solution would require a fair amount of work and maintenance - and I don't see Sun doing that. Can't be sure of that however.Palimpsest
A solution for the most widespread display managers would be enough.Jehoash
T
0

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

FileSystemView view = FileSystemView.getFileSystemView();
Icon icon = view.getSystemIcon(file);
Tailband answered 16/6, 2010 at 10:10 Comment(1)
No. Already tried that. It will only return some icons for windows system, for OSX and unix you get the default directory and folder icon of the UI. So I switched to new JFileChooser().getIcon(File f) which returns the file and folder icons for windows and OSX.Jehoash
O
0

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.

Overvalue answered 21/6, 2010 at 17:5 Comment(1)
Currently working on a window manager specific implementation. An answer in the link of user336851 mentioned xdg-mime, which I'm trying to use. Until now I only get a desktop file (no absolute path, only the name). Any idea how to go on?Jehoash

© 2022 - 2024 — McMap. All rights reserved.