我正在制作一个具有以下布局 (MigLayout
) 的 Java Swing 应用程序:
[icon][icon][icon][....]
where icon = jlabel and the user can add more icons
当用户添加或删除图标时,其他图标应该缩小或增长。
我的问题很简单:我有一个 JLabel
,其中包含一个 ImageIcon
;如何调整此图标的大小?
最佳答案
试试这个:
ImageIcon imageIcon = new ImageIcon("./img/imageName.png"); // load the image to a imageIcon
Image image = imageIcon.getImage(); // transform it
Image newimg = image.getScaledInstance(120, 120, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
imageIcon = new ImageIcon(newimg); // transform it back
(找到它here)
关于java - 如何调整 JLabel ImageIcon 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6714045/