Search code examples
javaswingimageiconjpopupmenu

Force a certain icon size for JPopupMenu items?


In my program I have Actions that have different-sized icons, some intended for large buttons and some for small. I would like to reuse the same instance of each of these Actions when adding functionality to a JPopupMenu. Is there a way to force the large icons to be displayed at a smaller size?


Solution

  • The Actions API provides two icon keys. SMALL_ICON and LARGE_ICON_KEY

    From the JavaDocs

    The JMenuItem subclasses only use SMALL_ICON. All other buttons will use LARGE_ICON_KEY; if the value is null they use SMALL_ICON.

    This would suggest that you should use the SMALL_ICON key for your actions to allow JMenuItems to display the small icon.