I had the same problem. Here's what I did.import java.awt.*;
import javax.swing.*;
// Move Menu up if it extends off bottom of component (or scrollpane if inside one)
public class SmartPopupMenu extends JPopupMenu {
public SmartPopupMenu() { }
public SmartPopupMenu(String label) { super(label); }
public void show(Component invoker, int x, int y) {
Component parent=invoker;
int newx = x, newy = y;
while (parent != null &&!(parent instanceof JScrollPane)) {
newx += parent.getX();
newy += parent.getY();
parent = parent.getParent();
}
if (parent!=null) {
invoker=parent;
x=newx; y=newy;
}
super.show(invoker, x, y);
Rectangle menuBounds = getBounds();
Rectangle invokerBounds = invoker.getBounds();
if (y+menuBounds.height > invokerBounds.height) {
Point invokerLoc = invoker.getLocationOnScreen();
setLocation(x+invokerLoc.x,invokerLoc.y+invokerBounds.height-menuBounds.height);
}
}
}