0

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

MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125

2 Answers2

5

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);
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
0

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:

Community
  • 1
  • 1
Hendrik Ebbers
  • 2,570
  • 19
  • 34