File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JPopupMenu or JMenu - neither is quite what I'm after. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPopupMenu or JMenu - neither is quite what I Watch "JPopupMenu or JMenu - neither is quite what I New topic
Author

JPopupMenu or JMenu - neither is quite what I'm after.

Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38
I'd like a little popup menu to appear when I click on a button, I would like the menu to highlight the background of each menu item as the mouse moves over it.

This doesn't happen with a JPopupMenu, it works with a JMenu but I can't figure out how to trigger the menu without having a JMenuBar.

So, is there a way of making the JPopupMenu highlight elements? Or way to create a JMenu without a menu bar?

I've tried, menu.doClick(0); but that only works when the menu bar is also present.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 19351
    
  10

That's odd. When I run the PopupMenu Demo from the How to Use Menus tutorial, it behaves exactly the way you say you want it to behave.
Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38
When running that sample code I can't seem to see a popup menu, just the two menus at the top.

http://img522.imageshack.us/img522/6218/menuk.jpg

My code (below) works but the menu items don't highlight when I move the mouse over each menu item.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 19351
    
  10

Harold Lime wrote:When running that sample code I can't seem to see a popup menu, just the two menus at the top.


Um, you right-click the blank area and you get a popup menu.
Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38
Fixed.

It seems that not supplying a component to:



stops the menu items from highlighting.

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 19351
    
  10

Hmm. That wouldn't have been my first guess. Or even in the top ten guesses. Anyway glad you got it fixed.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 865
    
    1
Harold Lime wrote:Fixed.

It seems that not supplying a component to:

  • JPopupMenu.show(Component invoker, int x, int y)

  • stops the menu items from highlighting.


    FYI, you may continue to use setVisible(true) if you simply call popup.setInvoker(button) first.


    bitguru blog
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: JPopupMenu or JMenu - neither is quite what I'm after.