Java JPopupMenu showPopupCloseMenu(JPopupMenu popup, Component parentComponent)

Here you can find the source of showPopupCloseMenu(JPopupMenu popup, Component parentComponent)

Description

show Popup Close Menu

License

Open Source License

Declaration

public static void showPopupCloseMenu(JPopupMenu popup,
        Component parentComponent) 

Method Source Code

//package com.java2s;
import javax.swing.*;

import java.awt.*;

public class Main {

    public static void showPopupCloseMenu(JPopupMenu popup,
            Component parentComponent) {
        if (popup == null) {// check null.
            return;
        }//from   w  ww.  jav  a 2s.co m

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Window frame = SwingUtilities.getWindowAncestor(parentComponent);

        int leftX = 0;

        int rightX = parentComponent.getLocation().x
                + frame.getLocation().x + popup.getPreferredSize().width;
        if (rightX > screenSize.width) {
            leftX = screenSize.width - rightX;
        }

        popup.show(parentComponent, leftX, parentComponent.getSize().height);
    }
}

Related

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