MaVRoSCy
MaVRoSCy

Reputation: 17839

Program's executable file to image in Java

I know this might seem a bit odd, but i have this requirement and I want to know if this is possible.

I have a java swing application that I select a file (program) and this program is added to a list. When the list is completed, i execute the list of programs (this is like a start-up manager).

What I want to do is somehow, grab the file that I select and display it as image to my UI. For common files like pdf, doc, txt this is easy, I just have a generic image for each type. But lets say I want to execute regedit.exe or msconfig.exe, I want to be able to grab its icon (picture below) .

enter image description here

Does anyone know how this can be done?

Thanks

Upvotes: 0

Views: 205

Answers (2)

Hendrik Ebbers
Hendrik Ebbers

Reputation: 2600

If you want the native icons you need JNI. Java has no default API for fetching the native icons in different sizes. Here are some startingpoints for windows & linux:

If you do not need the exact native icons you can get the mimetype of the file and set a icon on your own:

Upvotes: 0

MadProgrammer
MadProgrammer

Reputation: 347314

Take a look at FileSystemView.getSystemIcon(File).

It's a little limited (in that you will only get one size), but it's build in and doesn't require any additional libraries or JNA or JNI even...

File f = new File(...);
Icon icon = FileSystemView.getFileSystemView().getSystemIcon(f);

Upvotes: 5

Related Questions