在 JButton 中调整 ImageIcon 的大小 [英] resizing a ImageIcon in a JButton

查看:34
本文介绍了在 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 );

来自 http://www.coderanch.com/t/331731/GUI/java/Resize-ImageIcon

这篇关于在 JButton 中调整 ImageIcon 的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆