public class MenuScroller extends java.lang.Object
Implementation note: The default scrolling interval is 150 milliseconds.
Modifier and Type | Class and Description |
---|---|
private static class |
MenuScroller.MenuIcon |
private class |
MenuScroller.MenuScrollItem |
private class |
MenuScroller.MenuScrollListener |
private class |
MenuScroller.MenuScrollTimer |
private class |
MenuScroller.MouseScrollListener |
Modifier and Type | Field and Description |
---|---|
private static int |
ARROW_ICON_HEIGHT |
private MenuScroller.MenuScrollItem |
downItem |
private int |
firstIndex |
private int |
interval |
private javax.swing.JPopupMenu |
menu |
private java.awt.Component[] |
menuItems |
private MenuScroller.MenuScrollListener |
menuListener |
private java.awt.event.MouseWheelListener |
mouseWheelListener |
private javax.swing.JComponent |
parent |
private int |
topFixedCount |
private MenuScroller.MenuScrollItem |
upItem |
Constructor and Description |
---|
MenuScroller(javax.swing.JComponent parentComp,
javax.swing.JMenu menu) |
MenuScroller(javax.swing.JComponent parentComp,
javax.swing.JMenu menu,
int interval) |
MenuScroller(javax.swing.JComponent parentComp,
javax.swing.JMenu menu,
int interval,
int topFixedCount) |
MenuScroller(javax.swing.JMenu menu)
Constructs a
MenuScroller that scrolls a menu with the
default scrolling interval. |
MenuScroller(javax.swing.JMenu menu,
int interval)
Constructs a
MenuScroller that scrolls a menu with the
specified scrolling interval. |
MenuScroller(javax.swing.JMenu menu,
int interval,
int topFixedCount)
Constructs a
MenuScroller that scrolls a menu with the
specified scrolling interval, and the specified numbers of items fixed at
the top of the menu. |
MenuScroller(javax.swing.JPopupMenu menu)
Constructs a
MenuScroller that scrolls a popup menu with the
default scrolling interval. |
MenuScroller(javax.swing.JPopupMenu menu,
int interval)
Constructs a
MenuScroller that scrolls a popup menu with the
specified scrolling interval. |
MenuScroller(javax.swing.JPopupMenu menu,
int interval,
int topFixedCount)
Constructs a
MenuScroller that scrolls a popup menu with the
specified scrolling interval, and the specified numbers of items fixed at
the top of the popup menu. |
Modifier and Type | Method and Description |
---|---|
private int |
computeScrollCount(int startIndex) |
void |
dispose()
Removes this MenuScroller from the associated menu and restores the
default behavior of the menu.
|
int |
getInterval()
Returns the scroll interval in milliseconds
|
static java.awt.Dimension |
getMaxDimensionOnScreen(javax.swing.JComponent parent,
javax.swing.JComponent component)
Computes the maximum dimension for a component to fit in screen
displaying
component . |
int |
getTopFixedCount()
Returns the number of items fixed at the top of the menu or popup menu.
|
private void |
refreshMenu() |
void |
resetMenu() |
void |
setInterval(int interval)
Sets the scroll interval in milliseconds
|
void |
setParent(javax.swing.JComponent parent) |
static MenuScroller |
setScrollerFor(javax.swing.JMenu menu)
Registers a menu to be scrolled with the default scrolling interval.
|
static MenuScroller |
setScrollerFor(javax.swing.JMenu menu,
int interval)
Registers a menu to be scrolled, with the specified scrolling interval.
|
static MenuScroller |
setScrollerFor(javax.swing.JMenu menu,
int interval,
int topFixedCount)
Registers a menu to be scrolled, with the specified scrolling interval,
and the specified numbers of items fixed at the top of the menu.
|
static MenuScroller |
setScrollerFor(javax.swing.JPopupMenu menu)
Registers a popup menu to be scrolled with the default scrolling interval.
|
static MenuScroller |
setScrollerFor(javax.swing.JPopupMenu menu,
int interval)
Registers a popup menu to be scrolled, with the specified scrolling interval.
|
static MenuScroller |
setScrollerFor(javax.swing.JPopupMenu menu,
int interval,
int topFixedCount)
Registers a popup menu to be scrolled, with the specified scrolling interval,
and the specified numbers of items fixed at the top of the popup menu.
|
void |
setTopFixedCount(int topFixedCount)
Sets the number of items to fix at the top of the menu or popup menu.
|
private javax.swing.JComponent parent
private javax.swing.JPopupMenu menu
private java.awt.Component[] menuItems
private MenuScroller.MenuScrollItem upItem
private MenuScroller.MenuScrollItem downItem
private final MenuScroller.MenuScrollListener menuListener
private final java.awt.event.MouseWheelListener mouseWheelListener
private int interval
private int topFixedCount
private int firstIndex
private static final int ARROW_ICON_HEIGHT
public MenuScroller(javax.swing.JMenu menu)
MenuScroller
that scrolls a menu with the
default scrolling interval.menu
- the menujava.lang.IllegalArgumentException
- if scrollCount is 0 or negativepublic MenuScroller(javax.swing.JComponent parentComp, javax.swing.JMenu menu)
public MenuScroller(javax.swing.JPopupMenu menu)
MenuScroller
that scrolls a popup menu with the
default scrolling interval.menu
- the popup menujava.lang.IllegalArgumentException
- if scrollCount is 0 or negativepublic MenuScroller(javax.swing.JMenu menu, int interval)
MenuScroller
that scrolls a menu with the
specified scrolling interval.menu
- the menuinterval
- the scroll interval, in millisecondsjava.lang.IllegalArgumentException
- if scrollCount or interval is 0 or negativepublic MenuScroller(javax.swing.JPopupMenu menu, int interval)
MenuScroller
that scrolls a popup menu with the
specified scrolling interval.menu
- the popup menuinterval
- the scroll interval, in millisecondsjava.lang.IllegalArgumentException
- if scrollCount or interval is 0 or negativepublic MenuScroller(javax.swing.JComponent parentComp, javax.swing.JMenu menu, int interval)
public MenuScroller(javax.swing.JMenu menu, int interval, int topFixedCount)
MenuScroller
that scrolls a menu with the
specified scrolling interval, and the specified numbers of items fixed at
the top of the menu.menu
- the menuinterval
- the scroll interval, in millisecondstopFixedCount
- the number of items to fix at the top. May be 0java.lang.IllegalArgumentException
- if scrollCount or interval is 0 or
negative or if topFixedCount is negativepublic MenuScroller(javax.swing.JComponent parentComp, javax.swing.JMenu menu, int interval, int topFixedCount)
public MenuScroller(javax.swing.JPopupMenu menu, int interval, int topFixedCount)
MenuScroller
that scrolls a popup menu with the
specified scrolling interval, and the specified numbers of items fixed at
the top of the popup menu.menu
- the popup menuinterval
- the scroll interval, in millisecondstopFixedCount
- the number of items to fix at the top. May be 0java.lang.IllegalArgumentException
- if scrollCount or interval is 0 or
negative or if topFixedCount is negativepublic static java.awt.Dimension getMaxDimensionOnScreen(javax.swing.JComponent parent, javax.swing.JComponent component)
component
.component
- The component to get current screen info from.
Must not be null
java.lang.NullPointerException
- if component
is null
.private int computeScrollCount(int startIndex)
public static MenuScroller setScrollerFor(javax.swing.JMenu menu)
menu
- Menu topublic static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu)
menu
- the popup menupublic static MenuScroller setScrollerFor(javax.swing.JMenu menu, int interval)
menu
- the menuinterval
- the scroll interval, in millisecondsjava.lang.IllegalArgumentException
- if scrollCount or interval is 0 or negativepublic static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu, int interval)
menu
- the popup menuinterval
- the scroll interval, in millisecondsjava.lang.IllegalArgumentException
- if scrollCount or interval is 0 or negativepublic static MenuScroller setScrollerFor(javax.swing.JMenu menu, int interval, int topFixedCount)
menu
- the menuinterval
- the scroll interval, in millisecondstopFixedCount
- the number of items to fix at the top. May be 0.java.lang.IllegalArgumentException
- if scrollCount or interval is 0 or
negative or if topFixedCount is negativepublic static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu, int interval, int topFixedCount)
menu
- the popup menuinterval
- the scroll interval, in millisecondstopFixedCount
- the number of items to fix at the top. May be 0java.lang.IllegalArgumentException
- if scrollCount or interval is 0 or
negative or if topFixedCount is negativepublic int getInterval()
public void setInterval(int interval)
interval
- the scroll interval in millisecondsjava.lang.IllegalArgumentException
- if interval is 0 or negativepublic int getTopFixedCount()
public void setTopFixedCount(int topFixedCount)
topFixedCount
- the number of itemspublic void dispose()
public void resetMenu()
public void setParent(javax.swing.JComponent parent)
private void refreshMenu()