JMenuBar and Popups
Hope you can help with this as I'm out of idea's on how to achieve it.
I have a small app with a JMenuBar, a number of JMenu's which contain a number of JMenuItems, all very straightforward so far.
The default behaviour of any JMenu is to appear within a popup below the JMenuBar item that has been selected but what I'm trying to do it to change this default functionality.
I am trying to reposition the JMenu popup to another position on the screen relative to the JMenuBar button selected. For instance I would like to position it 100 pixels lower than it is by default.
I would prefer however not to do this by simply creating an action listener and reponding to say a mouse event. I have done something similiar for a JCombo box by replacing it's UI delegate and overriding the "createPopup()" method and dynamically repositioning the popup it creates from there. I'm looking for suggestions/examples of something similiar if anyone has any idea.
Use a MenuListener. The menuSelected(MenuEvent) method is called before the popup is made visible, so you can request the popup's location by calling setMenuLocation(x, y) on the JMenu within said method.
Hi aephyr, thanks for your reply.
Although this is a good option and one I can fall back on, for my purposes I would prefer not to use a listener.
Does anyone else have any other options?