Results 1 to 3 of 3
  1. #1
    snoopygee is offline Member
    Join Date
    Dec 2010
    Posts
    7
    Rep Power
    0

    Default JMenuBar and Popups

    Hi all,

    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.

    Thanks again.

  2. #2
    aephyr is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    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.

  3. #3
    snoopygee is offline Member
    Join Date
    Dec 2010
    Posts
    7
    Rep Power
    0

    Default

    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?
    Last edited by snoopygee; 12-10-2010 at 11:09 AM.

Similar Threads

  1. Annoying Popups
    By camickr in forum Suggestions & Feedback
    Replies: 24
    Last Post: 03-01-2011, 04:58 PM
  2. Mutliple JMenuBar
    By chyrl in forum AWT / Swing
    Replies: 10
    Last Post: 11-04-2010, 06:43 AM
  3. Changing position of JMenuBar
    By LianaN in forum New To Java
    Replies: 8
    Last Post: 09-17-2010, 01:41 PM
  4. JMenubar option
    By navishkumarb in forum New To Java
    Replies: 3
    Last Post: 05-24-2010, 03:03 AM
  5. Create JMenuBar using DataBase
    By arulmozs in forum AWT / Swing
    Replies: 1
    Last Post: 11-03-2009, 12:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •