Class MenuUtilities


  • public class MenuUtilities
    extends Object
    Menu-related utilities.
    • Constructor Detail

      • MenuUtilities

        public MenuUtilities()
    • Method Detail

      • getMenuLayoutInfo

        public static MenuUtilities.MenuLayoutInfo getMenuLayoutInfo​(boolean forPainting,
                                                                     JMenuItem menuItem,
                                                                     Font acceleratorFont,
                                                                     Icon checkIcon,
                                                                     Icon arrowIcon,
                                                                     int defaultTextIconGap)
        Returns the layout info for the specified menu item.
        Parameters:
        menuItem - Menu item.
        acceleratorFont - Font for the accelerator text.
        checkIcon - Check icon.
        arrowIcon - Arrow icon.
        defaultTextIconGap - Gap between the icon and the text.
        Returns:
        Layout info for the specified menu item.
      • paintMenuItem

        public static void paintMenuItem​(Graphics g,
                                         JMenuItem menuItem,
                                         Icon checkIcon,
                                         Icon arrowIcon,
                                         int defaultTextIconGap)
        Paints the specified menu item.
        Parameters:
        g - Graphics context.
        menuItem - Menu item.
        checkIcon - Check icon.
        arrowIcon - Arrow icon.
        defaultTextIconGap - Gap between the icon and the text.
      • getMetrics

        protected static MenuUtilities.MenuLayoutMetrics getMetrics​(JPopupMenu popupMenu,
                                                                    boolean forPainting)
        Returns the layout metrics of the specified popup menu.
        Parameters:
        popupMenu - Popup menu.
        Returns:
        Layout metrics of the specified popup menu.
      • getPopupLayoutMetrics

        public static MenuUtilities.MenuLayoutMetrics getPopupLayoutMetrics​(JMenuItem menuItem,
                                                                            boolean forPainting)
        Returns the layout metrics of the popup menu of the specified menu item.
        Parameters:
        menuItem - Menu item.
        Returns:
        Layout metrics of the popup menu of the specified menu item.
      • cleanPopupLayoutMetrics

        public static void cleanPopupLayoutMetrics​(JPopupMenu popupMenu)
        Cleans the layout metrics of the specified popup menu.
        Parameters:
        popupMenu - Popup menu.
      • getPreferredWidth

        public static int getPreferredWidth​(JMenuItem menuItem)
        Returns the preferred width of the specified menu item. The preferred width depends on the layout metrics of the entire popup menu of this menu item.
        Parameters:
        menuItem - Menu item.
        Returns:
        Preferred width of the specified menu item
      • getTextOffset

        public static int getTextOffset​(JComponent menuItem,
                                        Component menuItemParent)
        Returns the text offset of the specified menu item.
        Parameters:
        menuItem - Menu item.
        menuItemParent - Menu item parent.
        Returns:
        Text offset of the specified menu item.