-2

This is the code

btnVoltar.setIcon(new ImageIcon(AdicionarRefeição1.class.getResource("/icons/Back Icon.png")));

I want to resize it so it fits on a label, but its way too big.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
In Yumen
  • 31
  • 7
  • I think you're thinking backwards, but, `ImageIO.read` will allow you to load an image from the resource bundle, then you could use something like [this](https://stackoverflow.com/questions/11959758/java-maintaining-aspect-ratio-of-jpanel-background-image/11959928#11959928) or [this](https://stackoverflow.com/questions/25798156/resizing-icon-to-fit-on-jbutton-in-java/25798462#25798462) to scale it – MadProgrammer Jul 17 '18 at 01:14
  • 1
    How big is "way too big"? 100px? 1000px? Size of Texas? Size of Alaska? Size of the Great Red Spot? – Robert Columbia Jul 17 '18 at 01:44

1 Answers1

0

You can try this codes here, but then again this post is a duplicate from stackoverflow

private ImageIcon image; // where in your case it's your class resource
        Image IMG = image.getImage(); // transform it 
        Image newimg = IMG.getScaledInstance(200, 200,  java.awt.Image.SCALE_SMOOTH); // scale it the smooth way 
//Change the 200,200 to the number you prefer to resize it to
        image = new ImageIcon(newimg);  // transform it back
Matt
  • 76
  • 1
  • 10