问题
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:
- Use the Swing classes referenced in the similar question.
Extract a BufferedImage from the icons, using:
- How to convert Icon from JLabel into BufferedImage?
- 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