Java JMenuItem getMenuItemParent(JMenuItem menuItem)

Here you can find the source of getMenuItemParent(JMenuItem menuItem)

Description

Returns parent of this component if it is not a top-level menu Otherwise returns null.

License

Open Source License

Parameter

Parameter Description
menuItem the menu item whose parent will be returned.

Return

parent of this component if it is not a top-level menu Otherwise returns null.

Declaration

public static JComponent getMenuItemParent(JMenuItem menuItem) 

Method Source Code

//package com.java2s;
/*/*w  ww.  j a  va2s .co m*/
 * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

import javax.swing.*;

import java.awt.*;

public class Main {
    private JComponent miParent;
    private boolean isTopLevelMenu;

    /**
     * Returns parent of this component if it is not a top-level menu
     * Otherwise returns null.
     * @param menuItem the menu item whose parent will be returned.
     * @return parent of this component if it is not a top-level menu
     * Otherwise returns null.
     */
    public static JComponent getMenuItemParent(JMenuItem menuItem) {
        Container parent = menuItem.getParent();
        if ((parent instanceof JComponent)
                && (!(menuItem instanceof JMenu) || !((JMenu) menuItem).isTopLevelMenu())) {
            return (JComponent) parent;
        } else {
            return null;
        }
    }

    public JComponent getMenuItemParent() {
        return miParent;
    }

    public boolean isTopLevelMenu() {
        return isTopLevelMenu;
    }
}

Related

  1. exit(JMenuItem anItem)
  2. getForeground(final BasicMenuItemUI ui, final JMenuItem menuItem)
  3. getIconPlaceholderWidth(final JMenuItem menuItem, final boolean alignTextToMenuIcons)
  4. getInvoker(final JMenuItem menuItem)
  5. getJMenuItem(String name, JMenuBar jmenubar)
  6. getTopLevelMenu(JMenuItem menuitem)
  7. layoutMenuItem(JMenuItem menuItem, FontMetrics fm, String text, FontMetrics fmAccel, String acceleratorText, Icon icon, Icon checkIcon, Icon arrowIcon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewRect, Rectangle iconRect, Rectangle textRect, Rectangle acceleratorRect, Rectangle checkIconRect, Rectangle arrowIconRect, int textIconGap, int menuItemGap)
  8. linkMenuItem(final JMenuItem master, final JMenuItem slave)
  9. pintaBarraMenu(Graphics g, JMenuItem menuItem, Color bgColor)