Search code examples
javaimageswingjlabel

How can I get my JLabel Icon Images to be high resolution?


I want to make an application with a small jLabel(50x50) in its corner.

The Problem I now have is that the Image the Label displays is looking really bad.

I also added the same Image as an Icon to a shortcut in windows on my desktop just as a comparison.

Windows on the left side and Java JLabel on the right.

How can I archive a similar scaling result in Jave with no loss in quality?

It does not need to use JLabel.

Code:

    ImageIcon imgIcon = new ImageIcon(path);
    Image img = imgIcon.getImage();
    Image imgScaled = img.getScaledInstance((int) (getWidth()), (int) (getHeight()), 
    Image.SCALE_SMOOTH);

    ImageIcon image = new ImageIcon(imgScaled);
    label.setIcon(image);

EDIT:

If you look at these Google Chrome Icons, they are extremely tiny but still sharp and high resolution, how can I archive this in Java?


Solution

  • Your can to use in BufferedImage, this is much higher resolution the JLabel. You can to create BufferedImage from .png file with ImageIO class.