我正在尝试显示 JEditorpane 文件扩展的系统图标,但只能显示最后一个图标?我想在换行符上附加并显示每个图标?
String fileList[] = {".pdf", ".txt", ".doc", ".exe"}
JLabel label;
FileSystemView fsv = FileSystemView.getFileSystemView();
icon = fsv.getSystemIcon(File.createTempFile("file.", "." + filetype[i]));
label = new JLabel(icon);
StyleContext context = new StyleContext();
StyledDocument document = new DefaultStyledDocument(context);
Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
StyleConstants.setComponent(labelStyle, label);
try {
document.insertString(document.getLength(), "\n", labelStyle);
} catch (BadLocationException badLocationException) {
System.err.println("Oops");
}
myjEditorPane.setDocument(document);