KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I wanted to create a JFileChooser with thumbnail view of image files.So I subclassed FileView and in the method which creates ImageIcon did some scaling sothat thumbnail images are shown. However,the overall effect is that, the filechooser widget takes some time before opening a directory and showing thumbnails..In createImageIcon() below,I need to call new ImageIcon() twice-once with the image filepath and next with the resized image as constructor argument.I think this is what slows the widget . Is there a more efficient alternative?Any suggestions/pointers most welcome. thanks, mark public static void main(String[] args) { JFileChooser chooser=new JFileChooser(); ThumbNailView thumbView=new ThumbNailView(); chooser.setFileView(thumbView); } class ThumbNailView extends FileView{ public Icon getIcon(File f){ Icon icon=null; if(isImageFile(f.getPath())){ icon=createImageIcon(f.getPath(),null); } return icon; } private ImageIcon createImageIcon(String path,String description) { if (path != null) { ImageIcon icon=new ImageIcon(path); Image img = icon.getImage() ; Image newimg = img.getScaledInstance( 16, 16, java.awt.Image.SCALE_SMOOTH ) ; return new ImageIcon(newimg); } else { System.err.println("Couldn't find file: " + path); return null; } } private boolean isImageFile(String filename){ //return true if this is image }
Tags (comma-separated)
Save Edits
Cancel