Java Swing: popup : display small icon in menu

∥☆過路亽.° 提交于 2019-12-08 04:39:19

问题


I have a right click popup menu that works fine.

I now want to add a little image next to the text.

I managed to display the image in the popupmenu but its the full size version.

what I want to know is:

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


回答1:


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 ) );


来源:https://stackoverflow.com/questions/6295195/java-swing-popup-display-small-icon-in-menu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!