Here you can find the source of getTextOffset(JComponent menuItem, Component menuItemParent)
Parameter | Description |
---|---|
menuItem | Menu item. |
menuItemParent | Menu item parent. |
public static int getTextOffset(JComponent menuItem, Component menuItemParent)
//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; } }