Here you can find the source of getMousePopupAdapter(final Component component, final JPopupMenu popup)
Parameter | Description |
---|---|
component | the target component, non null |
popup | the popup menu, non null |
public static MouseAdapter getMousePopupAdapter(final Component component, final JPopupMenu popup)
//package com.java2s; /*/* ww w.ja va2s. co m*/ * Copyright 2010-2012 The Advance EU 7th Framework project consortium * * This file is part of Advance. * * Advance 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 3 of * the License, or (at your option) any later version. * * Advance 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 Advance. If not, see * <http://www.gnu.org/licenses/>. * */ import java.awt.Component; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JPopupMenu; public class Main { /** * Creates a mouse popup adapter for the given component and popup menu. * @param component the target component, non null * @param popup the popup menu, non null * @return the mouse adapter */ public static MouseAdapter getMousePopupAdapter(final Component component, final JPopupMenu popup) { return new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { handlePopup(e); } @Override public void mouseReleased(MouseEvent e) { handlePopup(e); } private void handlePopup(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(component, e.getX(), e.getY()); } } }; } }