如何在 java netbeans IDE 8.1 中调整设置为图标的图像的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39192692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:10:23  来源:igfitidea点击:

How to resize an image set as an icon in java netbeans IDE 8.1

javanetbeans

提问by Dr.Geek Nerd

I am very new to Java, I have learned how to add images in a jLabelas an icon in netbeans, but the image acts in a notorious way that is it becomes too big in a way that only part of it can be seen.

我对 Java 很陌生,我已经学会了如何将图像jLabel作为图标添加到中netbeans,但是图像以一种臭名昭著的方式起作用,即它变得太大以至于只能看到它的一部分。

I have tried various ways but I didn't solve it, and most of the answers explain it by coding, a way which I am not familiar with.

各种方法都试过了,都没有解决,大部分答案都是通过编码来解释的,这种方式我不太熟悉。

So I am humbly asking for help on how i can make that image to fit on a small jLabel or if there is any other way to accomplish this. (The images are for a computer voting system that has has an image a check box and name.)

因此,我虚心寻求帮助,了解如何使该图像适合小 jLabel 或是否有任何其他方法可以实现此目的。(这些图像适用于具有图像、复选框和名称的计算机投票系统。)

回答by ΦXoc? ? Пepeúpa ツ

you can resize the image in the IDE...

您可以在 IDE 中调整图像大小...

enter image description here

在此处输入图片说明

or in SourceCode:

或在源代码中:

BufferedImage img;
try {
    img = ImageIO.read(new File("strawberry.jpg"));
} catch (IOException e) {
    e.printStackTrace();
}

BufferedImage dimg = img.getScaledInstance(64, 64,        Image.SCALE_SMOOTH);

ImageIcon imageIcon = new ImageIcon(dimg);