I am creating a user interface using Swing and I want to display the image in JLabel . The code I use is as follows:
JLabel label = new JLabel(new ImageIcon(ImageIO.read(new File("img.jpg"))));
This works fine if I use png images, but when it comes to jpg (just some of them), I get a red image (different than the one I see in Paint.NET). I used this image: img.jpg
So I tried (as an alternative):
Toolkit.getDefaultToolkit().createImage(new File("img.jpg").getAbsolutePath());
- Does anyone have an idea why this is happening? Is this a special
JPEG that is not supported? - I read on this forum that most people recommend using ImageIO ( here ). Why?
thanks a lot
user1612150
source share