I have a page with objects on it. The object locations are defined by Rectangle2D.Double
. When I move the mouse I check whether or not the a rectangle contains the mouse point.
If yes I want to show a hover-over menu of the object (so far only text).
What I have in the constructor is this
annnotationPopupMenu = new JPopupMenu();
annotationTextArea = new JTextArea(5,20);
annotationTextArea.setLineWrap(true);
annnotationPopupMenu.add(annotationTextArea);
and if I'm over an object I run this
annotationTextArea.setText(annotation.getContent());
annnotationPopupMenu.setLocation(MouseInfo.getPointerInfo().getLocation().x+30, MouseInfo.getPointerInfo().getLocation().y);
annnotationPopupMenu.setVisible(true);
If I leave the object
annnotationPopupMenu.setVisible(false);
is run. The problem I have now is that when I tab out of the application and the mouse was over an object the JPopupMenu is still visible even though the rest of the application is now behind the window I tabbed to.
What do I need to do that the JPopup menu will either go invisible or at least does not have priority over the window I tabbed to.
Below a MWE which just opens a PopupMenu which stays on top even alt-tabbing:
package popupmenutest;
import javax.swing.JPopupMenu;
import javax.swing.JTextArea;
public class PopupMenuTest
{
public static void main(String[] args)
{
JPopupMenu annotationPopupMenu = new JPopupMenu();
JTextArea annotationTextArea = new JTextArea(5,20);
annotationTextArea.setLineWrap(true);
annotationPopupMenu.setLocation(500, 400);
annotationPopupMenu.add(annotationTextArea);
annotationPopupMenu.setVisible(true);
}
}