aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes HELP! me pls i can't open image on JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "HELP! me pls i can Watch "HELP! me pls i can New topic
Author

HELP! me pls i can't open image on JLabel

duangna lim
Greenhorn

Joined: Apr 08, 2004
Posts: 2
i try to choose image file from JFilechooser to open on a label ,but i still can't open any image T__T is there any worng in my code
this is the function that use to chooser file:
public void OpenImage(){

JFileChooser fc = new JFileChooser();
fc.setMultiSelectionEnabled(false);
fc.addChoosableFileFilter(new ImageFilter());
fc.setFileView(new imageFileView());
fc.setAccessory(new imagePreview(fc));
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

int returnVal = fc.showOpenDialog(this);

if(returnVal == JFileChooser.CANCEL_OPTION)
{ file = null; }
else
{ file = fc.getSelectedFile();}

}/*end OpenImage*/

and i took the file value to the other function ,it's in the same class .

/********************************/
/*label for image*/
/********************************/
String ImgName = file.getPath();
ImgName = file.toString();
ImgName = ImgName.replace('\\','/');
Image image = Toolkit.getDefaultToolkit().getImage(ImgName);
ImageIcon Img = new ImageIcon(image);
JLabel photoLabel = new JLabel(Img);
photoLabel.setIcon(Img);

JPanel photoPanel = new JPanel();
photoPanel.add(photoLabel);
tell me pleasse what's worng with me
thanks for every help
Venkatesh Chitnis
Greenhorn

Joined: Nov 05, 2003
Posts: 9
Try this...
fc.setFileView(new ImageFileView());
fc.setAccessory(new ImagePreview(fc));
instead of
fc.setFileView(new imageFileView());
fc.setAccessory(new imagePreview(fc));
Fuqiang Zhao
Greenhorn

Joined: Jan 07, 2004
Posts: 24
Why not use the following code:
ImageIcon icon = new ImageIcon(file.toURL());
instead of your mass code:
String ImgName = file.getPath();
ImgName = file.toString();
ImgName = ImgName.replace('\\','/');
duangna lim
Greenhorn

Joined: Apr 08, 2004
Posts: 2
thanks for your help i'll try that
very thank you!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HELP! me pls i can't open image on JLabel