Java JPopupMenu setLocationOnScreen(JPopupMenu visibleMenu, int x, int y)

Here you can find the source of setLocationOnScreen(JPopupMenu visibleMenu, int x, int y)

Description

This method exists because popup menus can not be directly moved (the have to be hidden and re-shown).

License

Open Source License

Declaration

public static void setLocationOnScreen(JPopupMenu visibleMenu, int x, int y) 

Method Source Code

//package com.java2s;
/*/*ww  w .j  av a  2  s .  c om*/
 * Copyright 2001-2008 Aqris Software AS. All rights reserved.
 * 
 * This program is dual-licensed under both the Common Development
 * and Distribution License ("CDDL") and the GNU General Public
 * License ("GPL"). You may elect to use one or the other of these
 * licenses.
 */

import javax.swing.JPopupMenu;

import java.awt.Point;

public class Main {
    /**
     * This method exists because popup menus can not be directly moved
     * (the have to be hidden and re-shown).
     */
    public static void setLocationOnScreen(JPopupMenu visibleMenu, int x, int y) {
        Point invokerLocation = visibleMenu.getInvoker().getLocationOnScreen();
        visibleMenu.setVisible(false);

        visibleMenu.show(visibleMenu.getInvoker(), x - invokerLocation.x, y - invokerLocation.y);
    }
}

Related

  1. positionPopupMenu(final JPopupMenu popupMenu, final MouseEvent event, final Rectangle rectangle, final int dividerlocation)
  2. refreshPopup(JPopupMenu popup)
  3. removeConsecutiveSeparators(JPopupMenu popupMenu)
  4. removeExtraSeparators(JPopupMenu popup)
  5. removeTopAndBottomSeparators(JPopupMenu popupMenu)
  6. setPopupMenu(final JComponent component, final JPopupMenu popup)
  7. setPopupMenu(final JComponent component, final JPopupMenu popup)
  8. showButtonPopupMenu(AbstractButton button, JPopupMenu popup)
  9. showMenu(JPopupMenu menu, JButton button)