Class MenuScroller
-
- All Implemented Interfaces:
public class MenuScrollerA class that provides scrolling capabilities to a long menu dropdown or popup menu. A number of items can optionally be frozen at the top and/or bottom of the menu.
Implementation note: The default number of items to display at a time is 15, and the default scrolling interval is 125 milliseconds.
Class is slightly changed as per comments on the webpage
Darryl Burke (http://tips4java.wordpress.com/2009/02/01/menu-scroller/)
-
-
Field Summary
Fields Modifier and Type Field Description public intintervalpublic inttopFixedCountpublic intbottomFixedCount
-
Constructor Summary
Constructors Constructor Description MenuScroller(JMenu menu)Constructs a MenuScrollerthat scrolls a menu with the default number of items to display at a time, and default scrolling interval.MenuScroller(JPopupMenu menu)Constructs a MenuScrollerthat scrolls a popup menu with the default number of items to display at a time, and default scrolling interval.MenuScroller(JMenu menu, int scrollCount)Constructs a MenuScrollerthat scrolls a menu with the specified number of items to display at a time, and default scrolling interval.MenuScroller(JPopupMenu menu, int scrollCount)Constructs a MenuScrollerthat scrolls a popup menu with the specified number of items to display at a time, and default scrolling interval.MenuScroller(JMenu menu, int scrollCount, int interval)Constructs a MenuScrollerthat scrolls a menu with the specified number of items to display at a time, and specified scrolling interval.MenuScroller(JPopupMenu menu, int scrollCount, int interval)Constructs a MenuScrollerthat scrolls a popup menu with the specified number of items to display at a time, and specified scrolling interval.MenuScroller(JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)Constructs a MenuScrollerthat scrolls a menu with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the menu.MenuScroller(JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)Constructs a MenuScrollerthat scrolls a popup menu with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the popup menu.
-
Method Summary
Modifier and Type Method Description intgetInterval()Returns the scroll interval in milliseconds voidsetInterval(int interval)Sets the scroll interval in milliseconds intgetTopFixedCount()Returns the number of items fixed at the top of the menu or popup menu. voidsetTopFixedCount(int topFixedCount)Sets the number of items to fix at the top of the menu or popup menu. intgetBottomFixedCount()Returns the number of items fixed at the bottom of the menu or popup menu. voidsetBottomFixedCount(int bottomFixedCount)Sets the number of items to fix at the bottom of the menu or popup menu. static MenuScrollersetScrollerFor(JMenu menu)Registers a menu to be scrolled with the default number of items to display at a time and the default scrolling interval. static MenuScrollersetScrollerFor(JPopupMenu menu)Registers a popup menu to be scrolled with the default number of items to display at a time and the default scrolling interval. static MenuScrollersetScrollerFor(JMenu menu, int scrollCount)Registers a menu to be scrolled with the default number of items to display at a time and the specified scrolling interval. static MenuScrollersetScrollerFor(JPopupMenu menu, int scrollCount)Registers a popup menu to be scrolled with the default number of items to display at a time and the specified scrolling interval. static MenuScrollersetScrollerFor(JMenu menu, int scrollCount, int interval)Registers a menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval. static MenuScrollersetScrollerFor(JPopupMenu menu, int scrollCount, int interval)Registers a popup menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval. static MenuScrollersetScrollerFor(JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)Registers a menu to be scrolled, with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the menu. static MenuScrollersetScrollerFor(JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)Registers a popup menu to be scrolled, with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the popup menu. intgetscrollCount()Returns the number of items in the scrolling portion of the menu. voidkeepVisible(JMenuItem item)Scrolls the specified item into view each time the menu is opened. voidkeepVisible(int index)Scrolls the item at the specified index into view each time the menu is opened. voiddispose()Removes this MenuScroller from the associated menu and restores the default behavior of the menu. voidsetScrollCount(int scrollCount)Sets the number of items in the scrolling portion of the menu. -
-
Constructor Detail
-
MenuScroller
MenuScroller(JMenu menu)
Constructs aMenuScrollerthat scrolls a menu with the default number of items to display at a time, and default scrolling interval.- Parameters:
menu- the menu
-
MenuScroller
MenuScroller(JPopupMenu menu)
Constructs aMenuScrollerthat scrolls a popup menu with the default number of items to display at a time, and default scrolling interval.- Parameters:
menu- the popup menu
-
MenuScroller
MenuScroller(JMenu menu, int scrollCount)
Constructs aMenuScrollerthat scrolls a menu with the specified number of items to display at a time, and default scrolling interval.- Parameters:
menu- the menuscrollCount- the number of items to display at a time
-
MenuScroller
MenuScroller(JPopupMenu menu, int scrollCount)
Constructs aMenuScrollerthat scrolls a popup menu with the specified number of items to display at a time, and default scrolling interval.- Parameters:
menu- the popup menuscrollCount- the number of items to display at a time
-
MenuScroller
MenuScroller(JMenu menu, int scrollCount, int interval)
Constructs aMenuScrollerthat scrolls a menu with the specified number of items to display at a time, and specified scrolling interval.- Parameters:
menu- the menuscrollCount- the number of items to display at a timeinterval- the scroll interval, in milliseconds
-
MenuScroller
MenuScroller(JPopupMenu menu, int scrollCount, int interval)
Constructs aMenuScrollerthat scrolls a popup menu with the specified number of items to display at a time, and specified scrolling interval.- Parameters:
menu- the popup menuscrollCount- the number of items to display at a timeinterval- the scroll interval, in milliseconds
-
MenuScroller
MenuScroller(JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)
Constructs aMenuScrollerthat scrolls a menu with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the menu.- Parameters:
menu- the menuscrollCount- the number of items to display in the scrolling portioninterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top.bottomFixedCount- the number of items to fix at the bottom.
-
MenuScroller
MenuScroller(JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)
Constructs aMenuScrollerthat scrolls a popup menu with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the popup menu.- Parameters:
menu- the popup menuscrollCount- the number of items to display in the scrolling portioninterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top.bottomFixedCount- the number of items to fix at the bottom.
-
-
Method Detail
-
getInterval
int getInterval()
Returns the scroll interval in milliseconds
- Returns:
the scroll interval in milliseconds
-
setInterval
void setInterval(int interval)
Sets the scroll interval in milliseconds
- Parameters:
interval- the scroll interval in milliseconds
-
getTopFixedCount
int getTopFixedCount()
Returns the number of items fixed at the top of the menu or popup menu.
- Returns:
the number of items
-
setTopFixedCount
void setTopFixedCount(int topFixedCount)
Sets the number of items to fix at the top of the menu or popup menu.
- Parameters:
topFixedCount- the number of items
-
getBottomFixedCount
int getBottomFixedCount()
Returns the number of items fixed at the bottom of the menu or popup menu.
- Returns:
the number of items
-
setBottomFixedCount
void setBottomFixedCount(int bottomFixedCount)
Sets the number of items to fix at the bottom of the menu or popup menu.
- Parameters:
bottomFixedCount- the number of items
-
setScrollerFor
static MenuScroller setScrollerFor(JMenu menu)
Registers a menu to be scrolled with the default number of items to display at a time and the default scrolling interval.
- Parameters:
menu- the menu- Returns:
the MenuScroller
-
setScrollerFor
static MenuScroller setScrollerFor(JPopupMenu menu)
Registers a popup menu to be scrolled with the default number of items to display at a time and the default scrolling interval.
- Parameters:
menu- the popup menu- Returns:
the MenuScroller
-
setScrollerFor
static MenuScroller setScrollerFor(JMenu menu, int scrollCount)
Registers a menu to be scrolled with the default number of items to display at a time and the specified scrolling interval.
- Parameters:
menu- the menuscrollCount- the number of items to display at a time- Returns:
the MenuScroller
-
setScrollerFor
static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount)
Registers a popup menu to be scrolled with the default number of items to display at a time and the specified scrolling interval.
- Parameters:
menu- the popup menuscrollCount- the number of items to display at a time- Returns:
the MenuScroller
-
setScrollerFor
static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval)
Registers a menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval.
- Parameters:
menu- the menuscrollCount- the number of items to be displayed at a timeinterval- the scroll interval, in milliseconds- Returns:
the MenuScroller
-
setScrollerFor
static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval)
Registers a popup menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval.
- Parameters:
menu- the popup menuscrollCount- the number of items to be displayed at a timeinterval- the scroll interval, in milliseconds- Returns:
the MenuScroller
-
setScrollerFor
static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)
Registers a menu to be scrolled, with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the menu.
- Parameters:
menu- the menuscrollCount- the number of items to display in the scrolling portioninterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top.bottomFixedCount- the number of items to fix at the bottom.- Returns:
the MenuScroller
-
setScrollerFor
static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)
Registers a popup menu to be scrolled, with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the popup menu.
- Parameters:
menu- the popup menuscrollCount- the number of items to display in the scrolling portioninterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top.bottomFixedCount- the number of items to fix at the bottom.- Returns:
the MenuScroller
-
getscrollCount
int getscrollCount()
Returns the number of items in the scrolling portion of the menu.
- Returns:
the number of items to display at a time
-
keepVisible
void keepVisible(JMenuItem item)
Scrolls the specified item into view each time the menu is opened. Call this method with
nullto restore the default behavior, which is to show the menu as it last appeared.- Parameters:
item- the item to keep visible
-
keepVisible
void keepVisible(int index)
Scrolls the item at the specified index into view each time the menu is opened. Call this method with
-1to restore the default behavior, which is to show the menu as it last appeared.- Parameters:
index- the index of the item to keep visible
-
dispose
void dispose()
Removes this MenuScroller from the associated menu and restores the default behavior of the menu.
-
setScrollCount
void setScrollCount(int scrollCount)
Sets the number of items in the scrolling portion of the menu.
- Parameters:
scrollCount- the number of items to display at a time
-
-
-
-