1

I have a JavaFX application which permits the user to select a file. The file could be an application.

I want to display the file's icon in an JavaFX ImageView.

Is there a cross-platform solution to get such icon image and display it in an ImageView?

Voldemort
  • 17,552
  • 47
  • 139
  • 262
  • 1
    Have you looked at [`FileSystemView#getSystemIcon(file)`](http://docs.oracle.com/javase/8/docs/api/javax/swing/filechooser/FileSystemView.html#getSystemIcon-java.io.File-)? – ItachiUchiha May 28 '15 at 17:37
  • @ItachiUchiha no, I didn't know it was compatible with JavaFX's `ImageView`. How do I apply it? It returns a Swing `Icon` object. – Voldemort May 28 '15 at 18:09

1 Answers1

0

You can get the default system icon for a file by using FileSystemView:

ImageIcon icon = (ImageIcon) FileSystemView.getFileSystemView().getSystemIcon(file);
java.awt.Image image = icon.getImage();

You can later use SwingFXUtils to convert it to FX Image and set it to an ImageView.

Also go through JavaFX file listview with icon and file name.

Community
  • 1
  • 1
ItachiUchiha
  • 35,309
  • 10
  • 121
  • 173