Here you can find the source of showPopupCloseMenu(JPopupMenu popup, Component parentComponent)
public static void showPopupCloseMenu(JPopupMenu popup, Component parentComponent)
//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); } }