Hi All,

I am using ImageIcon to display an image, however, the image does not appear. See the code i am using below.

Can you see what the problem is?
The receivedImage will be taken out of an object it is stored in, and then i want to display it in the GUI I have created.

I am new to java, so I hope you can understand my explanation.

Thanks

// Display image
                 ImageIcon receivedIcon = new ImageIcon(this.receivedImage);
                 receivedImageLabel = new JLabel(receivedIcon);
                 this.setSize(300,300);
                  this.getContentPane().add("North", receivedImageLabel);
                 this.setVisible(true);
                 this.show();


                 // End of display image

I can now get a button to add, but the image doesn't appear on the button.

The image was unpacked from an array as it had been sent across the network. It appears to have unpacked as the algorithm ran with no errors, and I can run a getHeight() agaisnt it and get an int.

Any help appreciated

ImageIcon receivedIcon = new ImageIcon(receivedImage);
                 receivedImageLabel = new JButton("Hello",receivedIcon);
Member Avatar for iamthwee

I can now get a button to add, but the image doesn't appear on the button.

The image was unpacked from an array as it had been sent across the network. It appears to have unpacked as the algorithm ran with no errors, and I can run a getHeight() agaisnt it and get an int.

Any help appreciated

ImageIcon receivedIcon = new ImageIcon(receivedImage);
                 receivedImageLabel = new JButton("Hello",receivedIcon);

Have you defined the exact path to that particular image. What format is your image .jpeg .gif ?

Hi,

I have just used the variable name that i have assigned to it. The image arrived over the network. I think this is where the problem is.

Do i have to load the image somehow?

Thanks for the help.

Member Avatar for iamthwee

Trouble shooting tips.

1. Load your image locally. And try it.
2. Make sure you specify the same extension of you image file in your actual program.

Try putting your images directly on the c: drive. Then call it such as:

ImageIcon receivedIcon = new ImageIcon("c:\\image.jpg");

or something.

How to import image for Icon from image in the package of frame

how to import this image of the same package in the icon declartion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.