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

时间:2018-07-17 01:10:19

标签: java image swing jbutton jlabel

这是代码

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

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

1 个答案:

答案 0 :(得分:0)

您可以在此处尝试使用此代码,但随后该帖子还是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