public class Main { public static void main(String[] argv) {
JFileChooser chooser = new JFileChooser();
chooser.setAccessory(new MyAccessory(chooser));
chooser.showOpenDialog(null);
}
} class MyAccessory extends JComponent implements PropertyChangeListener { public MyAccessory(JFileChooser chooser) {
chooser.addPropertyChangeListener(this);
setPreferredSize(new Dimension(50, 50));
} public void propertyChange(PropertyChangeEvent evt) { if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
JFileChooser chooser = (JFileChooser) evt.getSource();
// Get the new selected file
File newFile = (File) evt.getNewValue();
repaint();
}
} public void paint(Graphics g) {
// Paint a preview of the selected file
}
}