Java JPopupMenu showPopupMenu(final JPopupMenu popup, final Component component, int x, int y)

Here you can find the source of showPopupMenu(final JPopupMenu popup, final Component component, int x, int y)

Description

show Popup Menu

License

LGPL

Declaration

public static void showPopupMenu(final JPopupMenu popup, final Component component, int x, int y) 

Method Source Code


//package com.java2s;
import java.awt.Component;
import java.awt.Dimension;

import java.awt.Point;

import java.awt.Toolkit;

import javax.swing.JPopupMenu;

import javax.swing.SwingUtilities;

public class Main {
    public static void showPopupMenu(final JPopupMenu popup, final Component component, int x, int y) {
        final Point p = new Point(x, y);
        SwingUtilities.convertPointToScreen(p, component);
        final Dimension size = popup.getPreferredSize();
        final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

        boolean horiz = false;
        boolean vert = false;

        final int origX = x;

        if ((p.x + size.width > screen.width) && (size.width < screen.width)) {
            x += (screen.width - p.x - size.width);
            horiz = true;//ww w . j a v  a2 s  .c  o  m
        }

        if ((p.y + size.height > screen.height) && (size.height < screen.height)) {
            y += (screen.height - p.y - size.height);
            vert = true;
        }

        if (horiz && vert) {
            x = origX - size.width - 2;
        }
        popup.show(component, x, y);
    }
}

Related

  1. showMenu(JPopupMenu menu, JButton button)
  2. showModal(javax.swing.JPopupMenu popupMenu, java.awt.Component invoker, java.awt.Point pt)
  3. showPopMenuWithParentWidth(JPopupMenu popup, Component parentComponent, int x, int y)
  4. showPopup(JPopupMenu popup, MouseEvent event)
  5. showPopupCloseMenu(JPopupMenu popup, Component parentComponent)
  6. showPopupMenu(javax.swing.JPopupMenu popup, Component comp, int x, int y)
  7. showPopupMenu(javax.swing.JPopupMenu popup, Component comp, int x, int y)
  8. showPopupMenu(JPopupMenu menu, Component invoker, MouseEvent e)
  9. showPopupMenu(JPopupMenu popup, Component comp, int x, int y)