OK It works well. I took this idea and this article .
The idea is that I create a classic JList , but add a custom ListCellRenderer to draw icons that come from temporary files through JFileChooser . The resulting visualizer looks like this (I made the fields static, so they are not recreated every time the JList is executed):
package app; import java.awt.Component; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.DefaultListCellRenderer; import javax.swing.Icon; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JList; public class PseudofileIconRenderer extends DefaultListCellRenderer { private static HashMap<String, Icon> extIcons = new HashMap<String, Icon>(); private static Pattern p = Pattern.compile("\\.\\w+$"); private static JFileChooser chooser = new JFileChooser(); @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); String filename = (String) value; Matcher m = p.matcher(filename); Icon i; String extension = m.find() ? m.group() : ""; if (extIcons.containsKey(extension)) { i = extIcons.get(extension); } else { File file; try { file = File.createTempFile("icon", extension); file.deleteOnExit(); i = chooser.getIcon(file); extIcons.put(extension, i); } catch (IOException ex) {
Then I can populate JList String s, which will represent the files.
source share