Sunday, October 16, 2011

How to preview image in JFileChooser

Preamble 

This article shows how to add image preview to a JFileChooser.

JDK and eclipse compatibility 

JDK version 1.3 with eclipse 3.3 is the minimum requirement.

Project overview 

The downloadable zip file contains an eclipse project which has a MainFrame class for GUI. Clicking on the button will launch the file chooser. Selecting an image will display a preview in the right pane.

Unzip the downloadable and load in the eclipse project. Make a run configuration for MainFrame class and you are all set.

Code usage

//attach image preview to FileChooser
ImagePreview preview = new ImagePreview(chooser);
chooser.setAccessory(preview);

Enjoy, if you like it please appreciate!

No comments:

Post a Comment