获取 Image/Icon 与 Java 中的文件扩展名相关联

Get Image/Icon associated with file extension in Java

如何获取与 Java 中的文件扩展名关联的 icon/image?

这应该可以解决问题:

Icon ico = javax.swing.filechooser.FileSystemView.getFileSystemView().getSystemIcon( file )

要在标签上显示它,只需将它添加到 JLabel: myJpanel.add(new JLabel(ico));