• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this...
fc.setFileView(new ImageFileView());
fc.setAccessory(new ImagePreview(fc));
instead of
fc.setFileView(new imageFileView());
fc.setAccessory(new imagePreview(fc));
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your help i'll try that
very thank you!!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic