Java examples for Swing:JMenu
Finds the parent JPopupMenu of the given component, it it is contained in the component tree of one.
/*/*from w w w . jav a 2 s . c o m*/ * UIUtil.java of project jchart2d, utility class for UI / Layout operations. * Copyright (C) 2004 - 2011 Achim Westermann. * * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA* If you modify or optimize the code in a useful way please let * me know. Achim.Westermann@gmx.de */ import java.awt.Component; import java.awt.Frame; import java.awt.Point; import java.awt.Window; import java.awt.event.MouseEvent; import javax.swing.JFrame; import javax.swing.JPopupMenu; public class Main{ /** * Finds the parent <code>JPopupMenu</code> of the given component, it it is * contained in the component tree of one. * <p> * * @param component * a potential sub component of a popup menu. * * @return the popup menu of the given component or null. */ public static JPopupMenu findPopupMenu(final Component component) { JPopupMenu result = null; Component comp = component; if (component instanceof JPopupMenu) { result = ((JPopupMenu) component); } else { comp = component.getParent(); if (comp != null) { result = UIUtil.findPopupMenu(comp); } } return result; } }