-1

Hi i am trying to resize the image icon which i tried to use the getScaled method but it's not working, i have attached a copy of the code below.

public Example (){
        JLabel l = new JLabel(new ImageIcon(getClass().getResource("gui/CheckLib.png")));
        Image resize = l.getScaled(200, 180, 18);
        l.setIcon(new ImageIcon(resize));

        setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.anchor = GridBagConstraints.SOUTHEAST;
        c.weightx = 1;
        c.fill = GridBagConstraints.HORIZONTAL;
        add(l);
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Reynolds
  • 9
  • 5

2 Answers2

3

Some research would have shown you that JLabel does not have a method called getScaled

Some more research would have lead you to Image#getScaledInstance

Some more research might have lead you to The Perils of Image.getScaledInstance()

Which might have lead you to Java: maintaining aspect ratio of JPanel background image

Now remember, ImageIcon wraps a java.awt.Image in an Icon interface

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
1

You can try Darryl's Stretch Icon. It will resize the image based on the space available to the icon.

camickr
  • 321,443
  • 19
  • 166
  • 288