JPopupMenu should not lose focus
Question about JPopupMenu behav开发者_开发百科ior. I would like the JPopupMenu not to loose focus when it comes up. Also when JPopupMenu is in focus, the user should be able to click/update other parts of the Applet.
Is this possible? Reason is that this JPopupMenu is displaying some codes and it needs to be kept open for reference.
This is what I have now but as soon as the user clicks on the main Applet JPopupMenu looses focus:
JPopupMenu popupMenu = new JPopupMenu();
popupMenu.show(component, x, y);
thanks for your help.
Don't use a JPopupMenu for this purpose.
You can use a non-modal JDialog as the "popup". Make the dialog undecorated and the border will not be painted. Make sure you specify the owner when you create the dialog. You can use the SwingUtilities.windowForComponent(..) method to get the Window to be used as the owner.
"The exact gesture that should bring up a popup menu varies by look and feel." See Bringing Up a Popup Menu for details about doing this in a platform-independent way. Also, consider extending JApplet
instead of Applet
.
精彩评论