I’ve just come across a need for a JPopupMenu with lots of menu items and found out scrolling support if not built on? Shock! Horror!
After using Google to look for options and finding everything over-engineered or doing some weird things like not supporting the keyboard I decided to create my own.
JScrollPopupMenu extends JPopupMenu but adds:
- top and bottom scroll buttons
- support for mouse and keyboard scrolling
- definable number of items to display before scrolling functionality kicks in
- controllable scrolling speed
Below is a Java Applet demonstrating JScrollPopupMenu functionality.
The same concept could be used to create multiple scrollable menus where the menu has many submenus with many items.
The source code for JScrollPopupMenu can be found here – JScrollPopupMenu.java.
The code has been documented with Javadoc so you can create your own documentation straight from the code.