如何调整在类路径资源中选择的标签中的图像大小?



这是代码

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

我想调整它的大小,使其适合标签,但它太大了。

您可以在这里尝试这些代码,但这篇文章与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

最新更新