本文介绍了调整JButton中的ImageIcon大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个包含特定ImageIcon的JButton。主要问题是原始图标大小比按钮大小大得多。结果显示按钮时,只能看到部分图标。什么是调整ImageIcon以使其适合JButton的方法?
I am creating a JButton which includes a specific ImageIcon. The main issue is that the original icon size is much bigger than the button size. As result when the button is displayed, only part of the icon can be seen. What is the method that "resize" an ImageIcon i n order to make it fit inside a JButton?
推荐答案
Image img = icon.getImage() ;
Image newimg = img.getScaledInstance( NEW_WIDTH, NEW_HEIGHT, java.awt.Image.SCALE_SMOOTH ) ;
icon = new ImageIcon( newimg );
来自
这篇关于调整JButton中的ImageIcon大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!