public void propertyChange(PropertyChangeEvent e) {
        String propertyName = e.getPropertyName();

        // Make sure we are responding to the right event.
        if (propertyName.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
            File selection = (File) e.getNewValue();
            String name;

            if (selection == null) return;
            else name = selection.getAbsolutePath();

            /*
            * Make reasonably sure we have an image format that AWT can
            * handle so we don't try to draw something silly.
            */
            if ((name != null)
                    && (name.toLowerCase().endsWith(".jpg") || name.toLowerCase().endsWith(".jpeg")
                    || name.toLowerCase().endsWith(".gif") || name.toLowerCase().endsWith(".png"))) {
                icon = new ImageIcon(name);
                image = icon.getImage();
                scaleImage();
                repaint();
            }
        }
    }