All Implemented Interfaces:
ComponentListener, KeyListener, MouseListener, MouseWheelListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, ChangeListener, ListSelectionListener

Shows a carousel offset to the left with a menu of actions on the right.
See Also:
  • Field Details

    • lastSelection

      private int lastSelection
      The last item selected
    • upButton

      private JCarouselMenu.UpDownButton upButton
      The button that is drawn when it is possible to scroll up
    • downButton

      private JCarouselMenu.UpDownButton downButton
      The button shown when you can scroll down
  • Constructor Details

    • JCarouselMenu

      public JCarouselMenu(ImageBorder border)
      Creates a new instance of JCarouselMenu
      Parameters:
      border - The border to use to draw items in the menu
    • JCarouselMenu

      public JCarouselMenu()
      Creates a new instance
  • Method Details

    • setUpDownColor

      public void setUpDownColor(Color color)
      Sets the color the up and down buttons are drawn
      Parameters:
      color - The desired color
    • getList

      public JList getList()
      Returns the list part of the carousel menu
      Returns:
      The JList object
    • setSelectedIndex

      public void setSelectedIndex(int i)
      Sets the selected item in the menu
      Parameters:
      i - The index of the item to select
    • add

      public Component add(Component component, String label)
      Adds a component to the carousel menu that will be brought into view when the user clicks on the associated item
      Parameters:
      component - The component
      label - The text to appear in the menu
      Returns:
      The created component
    • remove

      public void remove(Component component)
      Removes a component from the menu
      Overrides:
      remove in class Container
      Parameters:
      component - The component to remove
    • add

      @Deprecated public Component add(Image image, String label, int width, int height)
      Deprecated.
      Use add(Image, String) instead
      Adds an image to the menu.
      Parameters:
      image - The image
      label - The text
      width - Prefered width
      height - Prefered height
      Returns:
      The created component
    • add

      public Component add(Image image, String label)
      Adds an image (with a label) and returns the component created to represent them
      Parameters:
      image - The image to display
      label - The label to show
      Returns:
      The component created
    • add

      @Deprecated public Component add(Action action, int width, int height)
      Deprecated.
      Use add(imageURL) instead
      Adds an action to the menu
      Parameters:
      action - The action to add
      width - The width
      height - The height
      Returns:
      The created component
    • add

      public Component add(Action action)
      Adds an action to the list, creating a menu item and a carousel entry
      Parameters:
      action - The action to add
      Returns:
      The resultant component
    • add

      @Deprecated public Component add(String imageURL, String label, int width, int height)
      Deprecated.
      Use add(imageURL, label) instead
      Adds an image (through a URL) to the menu
      Parameters:
      imageURL - URL of the image
      label - Text message
      width - width
      height - height
      Returns:
      The created component
    • add

      public Component add(String imageURL, String label)
      Adds an image based on the imageURL and a text label, returning the component that is created as a result
      Parameters:
      imageURL - The URL of the image
      label - Text label to be shown in the menu
      Returns:
      The created component
    • getPreferredSize

      public Dimension getPreferredSize()
      Return the preferred size of the component
      Overrides:
      getPreferredSize in class JComponent
      Returns:
      The prefered dimensions of the component
    • stateChanged

      public void stateChanged(ChangeEvent e)
      Detect when the list selection changes, and respond by updating the state of the two "arrow" buttons. Contributed by Sebastian Charpentier.
      Specified by:
      stateChanged in interface ChangeListener
      Parameters:
      e - The state changed event
      See Also:
    • valueChanged

      public void valueChanged(ListSelectionEvent listSelectionEvent)
      Detect when the list selection changes, and respond by rotating the carousel to show that item
      Specified by:
      valueChanged in interface ListSelectionListener
      Parameters:
      listSelectionEvent - The list selection change event
    • processAction

      protected void processAction()
      Launch the action associated with the currently selected list item
    • mouseClicked

      public void mouseClicked(MouseEvent mouseEvent)
      Look to see if an item in the list is double clicked, and launch the action if it is
      Specified by:
      mouseClicked in interface MouseListener
      Parameters:
      mouseEvent - The mouse event
    • mousePressed

      public void mousePressed(MouseEvent mouseEvent)
      Don't Care *
      Specified by:
      mousePressed in interface MouseListener
      Parameters:
      mouseEvent - The mouse event
    • mouseReleased

      public void mouseReleased(MouseEvent mouseEvent)
      Don't Care *
      Specified by:
      mouseReleased in interface MouseListener
      Parameters:
      mouseEvent - The mouse event
    • mouseEntered

      public void mouseEntered(MouseEvent mouseEvent)
      Don't Care *
      Specified by:
      mouseEntered in interface MouseListener
      Parameters:
      mouseEvent - The mouse event
    • mouseExited

      public void mouseExited(MouseEvent mouseEvent)
      Don't Care *
      Specified by:
      mouseExited in interface MouseListener
      Parameters:
      mouseEvent - The mouse event
    • keyTyped

      public void keyTyped(KeyEvent keyEvent)
      Don't Care *
      Specified by:
      keyTyped in interface KeyListener
      Parameters:
      keyEvent - The key event
    • keyPressed

      public void keyPressed(KeyEvent keyEvent)
      Listen for key events, when we see one that looks like it should wrap, set up the lastSelection variable to trigger a change on release of the key
      Specified by:
      keyPressed in interface KeyListener
      Parameters:
      keyEvent - The key event
    • setCellImageBorder

      public void setCellImageBorder(ImageBorder imageBorder)
      Sets the image border used to draw around the items in the menu
      Parameters:
      imageBorder - The desired image border
    • setCellRenderer

      public void setCellRenderer(ListCellRenderer cellRenderer)
      Specifies the list cell renderer used to draw the items in the menu
      Parameters:
      cellRenderer - The list cell renderer
    • keyReleased

      public void keyReleased(KeyEvent keyEvent)
      If the wrap-around has detected the need to wrap, sets the selection to the value calculated when the key was first pressed.
      Specified by:
      keyReleased in interface KeyListener
      Parameters:
      keyEvent - The key event
    • mouseWheelMoved

      public void mouseWheelMoved(MouseWheelEvent mouseWheelEvent)
      Moves the selected menu up or down when the mouse wheel scrolls
      Specified by:
      mouseWheelMoved in interface MouseWheelListener
      Parameters:
      mouseWheelEvent - The mouse wheel event
    • setUpDownIcons

      public void setUpDownIcons(Icon upIcon, Icon downIcon)
      Sets icons to use to show the up and down buttons
      Parameters:
      upIcon - The icon to use for up
      downIcon - The icon to use for down
    • setMenuScrollColor

      public void setMenuScrollColor(Color color)
      Allows the background color to the menu (left side) to be set
      Parameters:
      color - Sets the background color to the menu