Java 코드를 사용하여 Linux (Ubuntu) 시스템의 파일 선택기에 이미지 축소판을 표시하는 방법. Windows 플랫폼에서 성공적으로 작동하는 몇 가지 코드를 이미 시도했습니다 (이 링크 : making jfilechooser show image thumbnails 참조).Linux에서 이미지 파일 선택기에 이미지 축소판을 표시하는 방법
public class ThumbnailFileChooser extends JFileChooser {
private static final int ICON_SIZE = 16;
private static final Image LOADING_IMAGE = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_INT_ARGB);
private final Pattern imageFilePattern = Pattern.compile(".+?\\.(png|jpe?g|gif|tiff?)$", Pattern.CASE_INSENSITIVE);
private final Map imageCache = new WeakHashMap();
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFileChooser chooser = new ThumbnailFileChooser();
chooser.showOpenDialog(null);
System.exit(1);
}
public ThumbnailFileChooser() {
super();
}
{
setFileView(new ThumbnailView());
}
private class ThumbnailView extends FileView {
private final ExecutorService executor = Executors.newCachedThreadPool();
public Icon getIcon(File file) {
if (!imageFilePattern.matcher(file.getName()).matches()) {
return null;
}
synchronized (imageCache) {
ImageIcon icon = imageCache.get(file);
if (icon == null) {
icon = new ImageIcon(LOADING_IMAGE);
imageCache.put(file, icon);
executor.submit(new ThumbnailIconLoader(icon, file));
}
return icon;
}
}
}
private class ThumbnailIconLoader implements Runnable {
private final ImageIcon icon;
private final File file;
public ThumbnailIconLoader(ImageIcon i, File f) {
icon = i;
file = f;
}
public void run() {
System.out.println("Loading image: " + file);
// Load and scale the image down, then replace the icon's old image with the new one.
ImageIcon newIcon = new ImageIcon(file.getAbsolutePath());
Image img = newIcon.getImage().getScaledInstance(ICON_SIZE, ICON_SIZE, Image.SCALE_SMOOTH);
icon.setImage(img);
// Repaint the dialog so we see the new icon.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
repaint();
}
});
}
}
}
하지만 리눅스에서는 창문처럼 작동하지 않습니다.
* "이미 Windows 플랫폼에서 성공적으로 작동하는 일부 코드를 시도했습니다."* 말하지 마시고, 보여주십시오! 더 나은 도움을 받으려면 [MCVE] 또는 [단락, 자체 포함, 올바른 예] (http://www.sscce.org/)를 게시하십시오. –
http://stackoverflow.com/questions/4096433/making-jfilechooser-show-image-thumbnails –