Fetch icons of my System

好久不见. 提交于 2021-02-11 06:58:21

问题


I have made a program which shows my C and D drive. But the icons which are coming in my output are the default icons of javaFx. I just want to show all icons of my system. For example for videos it should show the media icon for my system, not the default icon in javaFx.


回答1:


This question is similar to:

  • How do I get a file's icon in Java?

That related question does not provide a native JavaFX solution.

However, there is currently no native JavaFX solution, so it would be best to:

  1. Use the Swing classes referenced in the similar question.
  2. Extract a BufferedImage from the icons, using:

    • How to convert Icon from JLabel into BufferedImage?
  3. Use SwingFXUtils.toFXImage to convert the BufferedImage to a JavaFX Image.

The related question suggests (and I haven't tried it) to do:

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

Or (if OS X):

javax.swing.JFileChooser fc = new javax.swing.JFileChooser();
Icon icon = fc.getUI().getFileView(fc).getIcon(file);

After writing this answer, I found the following question which is similar (perhaps this is even a duplicate):

  • JavaFX file listview with icon and file name


来源:https://stackoverflow.com/questions/38145329/fetch-icons-of-my-system

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!