tags:

views:

29

answers:

2

I'm trying to create a simple picture viewer that will allow the user to click a button and then select an image from the file system and have that image displayed in a JLabel.

I'm not familiar with picture viewing, but I've done file referencing before.

+1  A: 

(This question sounds like it could be homework, so I'm answering in a way that will point you in the right direction without simply giving away the answer.)

Have a look at the JLabel constructor that takes an Icon parameter, and also the ImageIcon class.

Greg Hewgill
I understand how those would help me, but I'm trying to figure out how you would get the file from a file chooser
Chris V.
ok, so I'm getting this error:sun.awt.image.ImageFormatException: Unsupported color conversion request at sun.awt.image.JPEGImageDecoder.readImage(Native Method) at sun.awt.image.JPEGImageDecoder.produceImage(Unknown Source) at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source) at sun.awt.image.ImageFetcher.fetchloop(Unknown Source) at sun.awt.image.ImageFetcher.run(Unknown Source)
Chris V.
A: 

Try something like that:

ImageIcon icon = new ImageIcon([path to image],[description]);

label.setIcon(icon);

sergej
I think I can get the image to show up using the ImageIcon class, but I'm not sure how to get the file path from a file chooser.
Chris V.