public void propertyChange(PropertyChangeEvent e) {
        File selectedFile = fc.getSelectedFile();
        if(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(e.getPropertyName()) && selectedFile!=null) {
            preview = new ImageIcon(selectedFile.getPath());
            if(preview == null)
                return; // couldn't read in the image

            // scale it if needed
            int iw = preview.getIconWidth();
            int ih = preview.getIconHeight();
            float sw = iw / (float)WIDTH;
            float sh = ih / (float)HEIGHT;
            if(sh>1 || sw>1) {
                // need to scale: at least one dimension doesn't fit
                if(sw > sh)
                    preview = new ImageIcon(preview.getImage().getScaledInstance(WIDTH, -1, Image.SCALE_DEFAULT));
                else
                    preview = new ImageIcon(preview.getImage().getScaledInstance(-1, HEIGHT, Image.SCALE_DEFAULT));
            }
            repaint();
        }
        else if(selectedFile == null) {
            // nothing selected => no preview image
            preview = null;
            repaint();
        }
    }