Class MenuScroller

  • All Implemented Interfaces:

    
    public class MenuScroller
    
                        

    A 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

    Author:

    Darryl Burke (http://tips4java.wordpress.com/2009/02/01/menu-scroller/)

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Constructor Summary

      Constructors 
      Constructor Description
      MenuScroller(JMenu menu) Constructs a MenuScroller that scrolls a menu with the default number of items to display at a time, and default scrolling interval.
      MenuScroller(JPopupMenu menu) Constructs a MenuScroller that 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 MenuScroller that 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 MenuScroller that 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 MenuScroller that 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 MenuScroller that 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 MenuScroller that 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 MenuScroller that 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.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      int getInterval() Returns the scroll interval in milliseconds
      void setInterval(int interval) Sets the scroll interval in milliseconds
      int getTopFixedCount() Returns the number of items fixed at the top of the menu or popup menu.
      void setTopFixedCount(int topFixedCount) Sets the number of items to fix at the top of the menu or popup menu.
      int getBottomFixedCount() Returns the number of items fixed at the bottom of the menu or popup menu.
      void setBottomFixedCount(int bottomFixedCount) Sets the number of items to fix at the bottom of the menu or popup menu.
      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.
      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.
      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.
      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.
      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.
      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.
      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.
      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.
      int getscrollCount() Returns the number of items in the scrolling portion of the menu.
      void keepVisible(JMenuItem item) Scrolls the specified item into view each time the menu is opened.
      void keepVisible(int index) Scrolls the item at the specified index into view each time the menu is opened.
      void dispose() Removes this MenuScroller from the associated menu and restores the default behavior of the menu.
      void setScrollCount(int scrollCount) Sets the number of items in the scrolling portion of the menu.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MenuScroller

        MenuScroller(JMenu menu)
        Constructs a MenuScroller that 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 a MenuScroller that 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 a MenuScroller that scrolls a menu with the specified number of items to display at a time, and default scrolling interval.
        Parameters:
        menu - the menu
        scrollCount - the number of items to display at a time
      • MenuScroller

        MenuScroller(JPopupMenu menu, int scrollCount)
        Constructs a MenuScroller that scrolls a popup menu with the specified number of items to display at a time, and default scrolling interval.
        Parameters:
        menu - the popup menu
        scrollCount - the number of items to display at a time
      • MenuScroller

        MenuScroller(JMenu menu, int scrollCount, int interval)
        Constructs a MenuScroller that scrolls a menu with the specified number of items to display at a time, and specified scrolling interval.
        Parameters:
        menu - the menu
        scrollCount - the number of items to display at a time
        interval - the scroll interval, in milliseconds
      • MenuScroller

        MenuScroller(JPopupMenu menu, int scrollCount, int interval)
        Constructs a MenuScroller that scrolls a popup menu with the specified number of items to display at a time, and specified scrolling interval.
        Parameters:
        menu - the popup menu
        scrollCount - the number of items to display at a time
        interval - the scroll interval, in milliseconds
      • MenuScroller

        MenuScroller(JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)
        Constructs a MenuScroller that 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 menu
        scrollCount - the number of items to display in the scrolling portion
        interval - the scroll interval, in milliseconds
        topFixedCount - 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 a MenuScroller that 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 menu
        scrollCount - the number of items to display in the scrolling portion
        interval - the scroll interval, in milliseconds
        topFixedCount - 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 menu
        scrollCount - 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 menu
        scrollCount - 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 menu
        scrollCount - the number of items to be displayed at a time
        interval - 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 menu
        scrollCount - the number of items to be displayed at a time
        interval - 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 menu
        scrollCount - the number of items to display in the scrolling portion
        interval - the scroll interval, in milliseconds
        topFixedCount - 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 menu
        scrollCount - the number of items to display in the scrolling portion
        interval - the scroll interval, in milliseconds
        topFixedCount - 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 null to 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 -1 to 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