This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Harold Lime
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed.

It seems that not supplying a component to:



stops the menu items from highlighting.

Thanks
 
Paul Clapham
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic