public JLabel SetImage(String path) throws IOException {
        ImageIcon myPicture = new ImageIcon(path);//ImageIO.read(new File(path));
        JLabel picLabel = new JLabel();
        picLabel.setBounds(0, 0, 2, 2);
        picLabel.setIcon(myPicture);
        pnlImage.setLayout(null);
        pnlImage.add(picLabel);
        pnlImage.repaint();
        pnlImage.revalidate();
        return picLabel;
    }

    try {
    String Ref = txtRef.getText();
    SetImage();
    JLabel label = new JLabel();
    label = SetImage("C:\\Users\\Documents");
    App\\ImagesDoc_001.jpg");
    pnlImage.setLayout(null);
    pnlImage.add(label);
    pnlImage.repaint();
    pnlImage.revalidate();
    } catch (IOException ex)

can anyone help me with this piece of code.. i am trying to load an image but it isnt loading

Edited 4 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Perhaps the

label = SetImage("C:\\Users\\Documents");
App\\ImagesDoc_001.jpg");

is causing problems for you? I would bet you probably want

label = SetImage("C:\\Users\\Documents\\App\\ImagesDoc_001.jpg");

Can you post your current code?

Try debugging your code by creating a File object with the path to the image and printing out the File class's exists() method's value.

Edited 4 Years Ago by NormR1: n/a

} catch (IOException ex)

before i say much, is this your complete code? if not please post the complete code, because this to me is wrong it should be:

try {
}catch (IOException ex) {
//exception handling here
}

which if this is not your complete source is fine, but remeber when you say you are having problems and post code thats like that we are not sure if its an error or you just cut your code at a random section?

Edited 4 Years Ago by DavidKroukamp: n/a

This article has been dead for over six months. Start a new discussion instead.