0
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 by Ezzaral: Added code tags. Please use them to format any code that you post.

6
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by NormR1
1

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");
1

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 by NormR1: n/a

0
} 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 by DavidKroukamp: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.