java - 如何调整在类路径资源中选择的标签中的图像大小?
问题描述
这是代码
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
推荐阅读
- r - 有条件地在其他变量的同一列中添加带有变量的行
- angular - 有什么方法可以在角度渲染中使用 *ngFor 的前 5 个结果并在浏览器中显示,其余的可以随着时间的推移加载
- python - 如何使用 python 访问谷歌驱动器中的 SQLite 数据库?
- firebase - 需要自定义可以在 Angular 中使用的 firebase 电子邮件模板
- arrays - C 编程 - 从标准输入读取文本到动态数组或动态链表并打印
- linux - 多次使用同一个文件运行同一个脚本
- javascript - mongodb 聚合方法在 MongoSH 和我的代码中返回不同的结果
- python - 将响应转换为 .csv 文件格式时如何修复 Nan Error
- typescript - 赛普拉斯:打字稿自定义命令不起作用
- css - vercel.json - 如何在标题中排除多个目录?(正则表达式的路径)