I am creating a Swing-based application. One of the frames in that application displays a tree. When user clicks with a right mouse button on a tree node a popup menu apperas. My question is related to the positioning of that menu.
Does anyone has a code or an algorithm which allows to position a popup menu in such a way that the menu is always completely visible (that is it is not completetly or partially hidden by the edge of the screen or edge of the parent frame. That means it has to be positioned based on the cursor location as well as various edges. I am looking for a behavior similar to that of popup menus in Microsoft Windows Explorer in 95 and NT.
I am not looking for a general description of the approach I shoud take but rather for an exact algorithm or even better a code which implements such behavior.