3 Replies - 2635 Views - Last Post: 10 April 2012 - 03:53 AM Rate Topic: -----

#1 mirror   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 07-April 12

How to display an image in jLabel when selected through a file chooser

Posted 09 April 2012 - 01:30 PM

Hello,
I've been trying to display an image in a JLabel when selected through a FileChooser.
But the image is not displayed.

Any help is appreciated.
Is This A Good Question/Topic? 0
  • +

Replies To: How to display an image in jLabel when selected through a file chooser

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: How to display an image in jLabel when selected through a file chooser

Posted 09 April 2012 - 01:37 PM

Should work.
If you don't show your code how do you think we can fix your problem.

label.setIcon(new ImageIcon(fileReturnedByFileChooser));

This post has been edited by pbl: 09 April 2012 - 01:47 PM

Was This Post Helpful? 0
  • +
  • -

#3 mirror   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 07-April 12

Re: How to display an image in jLabel when selected through a file chooser

Posted 09 April 2012 - 10:23 PM

ok here is the code:

JFileChooser chooser = new JFileChooser();
int result = chooser.showOpenDialog(null);
switch (result) 
   {
        
        case JFileChooser.APPROVE_OPTION:

            File selectedFile = chooser.getSelectedFile();
            jLabel14.setIcon(new ImageIcon(selectedFile));  //Error:cannot find symbol(ImageIcon))
   } 


Actually it requires "jLabel14.setIcon(Icon icon)" but we are providing the "file" type.
Is there any other way.
Was This Post Helpful? 0
  • +
  • -

#4 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: How to display an image in jLabel when selected through a file chooser

Posted 10 April 2012 - 03:53 AM

do you have the required import statement ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1