本文介绍了Java Swing:弹出:在菜单中显示小图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个右键单击弹出菜单,工作正常。
I have a right click popup menu that works fine.
我现在想在文本旁边添加一个小图片。
I now want to add a little image next to the text.
我设法在popupmenu中显示图像,但是它是完整尺寸的版本。
I managed to display the image in the popupmenu but its the full size version.
我想知道的是:
有没有办法自动将图标大小调整为合适的尺寸(与文字相同),还是必须调整图像大小?
is there a way to automatically reize the icon to be the right size ( same as the text ) or do I have to resize the image?
Jason
推荐答案
您必须将Icon的大小调整为您想要的大小。类似于:
You have to resize the Icon to be whatever size you want it to be. Something like:
ImageIcon icon = new ImageIcon( ... );
Image image = icon.getImage().getScaledInstance(64, 64, Image.SCALE_SMOOTH);
JLabel label = new JLabel( new ImageIcon( image ) );
这篇关于Java Swing:弹出:在菜单中显示小图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!