aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Scrolling JMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Scrolling JMenu" Watch "Scrolling JMenu" New topic
Author

Scrolling JMenu

Jeff Storey
Ranch Hand

Joined: Oct 09, 2006
Posts: 118
Is there a way to add a scrollbar to a JMenu for menus with a long list of items?

Thanks.
Jeff Storey
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Here's an idea:
Jeff Storey
Ranch Hand

Joined: Oct 09, 2006
Posts: 118
Hi Craig:

I have actually been working on a solution similar to this one, although the problem seems to be when this scrolling menu is used as an item in a popup menu. I have a popup menu with 3 items, one of which is another menu (the scrolling menu), so I should be able to mouse over that and display the scrolling list of items. It works until I want to press the scroll bar. The popup menu thinks that I have clicked on another component and hides itself. Do you see what I'm saying and have any thoughts on how to get around this?

Thanks.
Jeff
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The popup menu thinks that I have clicked on another component and hides itself. Do you see what I'm saying and have any thoughts on how to get around this?
Yes, I ran into the same problem. You may have to write some plaf code to get around this. I'd start with both JMenu and BasicMenuUI and look for the behavior that you want to modify. You can often extend the class and override/modify a few things to get what you want. The behavior seems complex so I would guess that it wouldn't be productive to replicate everything in your custom component. You never know...
Jeff Storey
Ranch Hand

Joined: Oct 09, 2006
Posts: 118
In the meantime, I think I've found a hack to this solution. I use a second popup menu that is not actually an item in the first and just trick the menu to show that second popup menu (a BasicComboPopup) when the mouse is in the appropriate location. Seems to be doing the trick for the most part. I appreciate the help.

Jeff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scrolling JMenu