Pop up menu obscured by task bar

Hi,We have a pop up menu that users can initiate. It seems to be that (infrequently) a menu item is obscured by the windows taskbar. Is there a mechanism I can use to check available real estate to prevent this?Thank you for whatever advice may be on offer.Dan
[288 byte] By [danthony74] at [2007-9-27 21:03:28]
# 1

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);

}

}

}

bbritta at 2007-7-7 2:45:27 > top of Java-index,Archived Forums,Swing...
# 2
It has to show the popup before it can figure out it's size, so if it extends off the component, it displays, then jumps up a bit. I didn't need it to work for nested menus.
bbritta at 2007-7-7 2:45:27 > top of Java-index,Archived Forums,Swing...
# 3
Thanks very much. This is quite a neat solution - though I'm waiting to see if the users will sign off on it. Very much appreciated.Dan
danthony74 at 2007-7-7 2:45:27 > top of Java-index,Archived Forums,Swing...