Java Swing Menu Item getTextOffset(JComponent menuItem, Component menuItemParent)

Here you can find the source of getTextOffset(JComponent menuItem, Component menuItemParent)

Description

Returns the text offset of the specified menu item.

License

Open Source License

Parameter

Parameter Description
menuItem Menu item.
menuItemParent Menu item parent.

Return

Text offset of the specified menu item.

Declaration

public static int getTextOffset(JComponent menuItem,
        Component menuItemParent) 

Method Source Code

//package com.java2s;
import java.awt.Component;

import javax.swing.JComponent;

import javax.swing.JPopupMenu;

public class Main {
    /**//  ww w  . j  a  v  a2 s .c  om
     * Key to store the gutter X location. The value should be an instance of
     * {@link Integer}.
     */
    private static final String GUTTER_X = "substancelaf.internal.menus.gutterX";

    /**
     * Returns the text offset of the specified menu item.
     * 
     * @param menuItem
     *            Menu item.
     * @param menuItemParent
     *            Menu item parent.
     * @return Text offset of the specified menu item.
     */
    public static int getTextOffset(JComponent menuItem,
            Component menuItemParent) {
        if (!(menuItemParent instanceof JPopupMenu)) {
            return 0;
        }

        Object itemProp = menuItem.getClientProperty(GUTTER_X);
        if (itemProp instanceof Integer) {
            return (Integer) itemProp;
        }

        JPopupMenu popupMenu = (JPopupMenu) menuItemParent;
        Object parentProp = popupMenu.getClientProperty(GUTTER_X);
        if (parentProp instanceof Integer) {
            return (Integer) parentProp;
        }
        return 0;
    }
}

Related

  1. getMenuItemBorder()
  2. getMenuItemDisabledForegroundObject()
  3. getMenuItemParent()
  4. getResetAppSettingsMenuItem()
  5. getSynthContext(final MenuItemUI ui, final JComponent item)
  6. getTexturesMenuItem()
  7. getTopicsMenuItem(ActionListener l)
  8. isSynthUI(final MenuItemUI ui)
  9. loadMenuItem(String action)