Folks,

I've written an app which uses a JTree. From each node on the tree,
depending on the type of node, different popup menus are available. When the
user right-clicks a node very near the bottom of the frame, if the popup has
enough elements, it will go below the visible portion of the frame.

What I have done to circumvent this is get the height of the RootPane of the
JTree, calculate the location of the bottom location of the popup by getting
the evt.getY() and adding it to the height of the popup. If the popup will
go off the frame, I offset the Y argument to the JPopupMenu.show() by the
amount the popup will go out.

Since I am reusing the JPopupMenu, I need to show() it every time through,
otherwise it retains the height of the previous incarnation. To do this, I
set isVisible to false, show it, and the set isVisible to true again, and
then do my calculation.

My question is: is there another way here? I've noticed some applications
will throw a popup in the opposite direction if it's too close to a border;
i.e. flip it around either its top, bottom, right or left axis, depending on
the orientation of the nearest border. Is there a simple way to do this, or
do I have to start rearranging the elements in the popup?

Speed is an issue here, as the calculations are done between the time the
user clicks, and the popup is displayed.

Any help appreciated.

Jon
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to