Package org.zkoss.zul

Class Carousel

All Implemented Interfaces:
Serializable, Cloneable, Component, Scope, ComponentCtrl

public class Carousel extends XulElement
A carousel (slideshow) container. Children must be Carouselitem.

Default getZclass(): "z-carousel".

Since:
11.0.0
Author:
yuehfeng
See Also:
  • Constructor Details

    • Carousel

      public Carousel()
  • Method Details

    • getActiveIndex

      public int getActiveIndex()
      Returns the index of the currently active slide.

      Matches what renderProperties(org.zkoss.zk.ui.sys.ContentRenderer) actually sends to the client: when the stored _activeIndex exceeds the current child count (e.g. ZUL set activeIndex='5' before adding children), the value is clamped to count - 1 — or 0 when there are no slides — for both render and getter so callers never observe an index that doesn't correspond to a real slide.

    • setActiveIndex

      public void setActiveIndex(int activeIndex) throws WrongValueException
      Sets the index of the currently active slide.
      Parameters:
      activeIndex - the zero-based index of the slide to activate; must be in [0, slideCount-1] once the carousel has rendered. Setting a different value pushes the new value to the client via smartUpdate.
      Throws:
      WrongValueException - if the carousel has already rendered and activeIndex is outside [0, slideCount-1]. Before the first render the value is stored unchecked, because a ZUL page may set it above the carousel's own carouselitem children.
    • isAutoplay

      public boolean isAutoplay()
      Returns whether the carousel advances through its slides automatically.

      Default: false.

      Since:
      11.0.0
    • setAutoplay

      public void setAutoplay(boolean autoplay)
      Sets whether the carousel advances through its slides automatically.
      Parameters:
      autoplay - true to start advancing slides automatically (using the interval), false to leave navigation manual.
    • getInterval

      public int getInterval()
      Returns the autoplay interval in milliseconds.

      Default: 5000.

      Since:
      11.0.0
    • setInterval

      public void setInterval(int interval) throws WrongValueException
      Sets the autoplay interval in milliseconds.
      Throws:
      WrongValueException - if interval is less than 500ms — the animation cannot reliably finish (and screen readers cannot announce the slide change) inside a tighter window.
    • isShowArrows

      public boolean isShowArrows()
      Returns whether the previous/next navigation arrows are shown.

      Default: true.

      Since:
      11.0.0
    • setShowArrows

      public void setShowArrows(boolean showArrows)
      Sets whether the previous/next navigation arrows are shown.
      Parameters:
      showArrows - true to display the navigation arrows, false to hide them.
    • isShowIndicators

      public boolean isShowIndicators()
      Returns whether the slide indicators (the position dots) are shown.

      Default: true.

      Since:
      11.0.0
    • setShowIndicators

      public void setShowIndicators(boolean showIndicators)
      Sets whether the slide indicators (the position dots) are shown.
      Parameters:
      showIndicators - true to display the indicators, false to hide them.
    • isLoop

      public boolean isLoop()
      Returns whether the carousel wraps around from the last slide back to the first (and vice versa).

      Default: true.

      Since:
      11.0.0
    • setLoop

      public void setLoop(boolean loop)
      Sets whether the carousel wraps around from the last slide back to the first (and vice versa).
      Parameters:
      loop - true to wrap around continuously, false to stop at the ends.
    • isPause

      public boolean isPause()
      Whether autoplay pauses while the cursor hovers over the carousel. Mirrors Bootstrap's data-bs-pause="hover" behavior.

      Default: true.

      Since:
      11.0.0
    • setPause

      public void setPause(boolean pause)
      Sets whether autoplay pauses while the cursor hovers over the carousel.
      Parameters:
      pause - true to pause autoplay on hover, false to keep advancing.
    • isKeyboard

      public boolean isKeyboard()
      Whether the carousel reacts to left/right arrow keys when focused. Mirrors Bootstrap's keyboard option.

      Default: true.

      Since:
      11.0.0
    • setKeyboard

      public void setKeyboard(boolean keyboard)
      Sets whether the carousel reacts to left/right arrow keys when focused.
      Parameters:
      keyboard - true to enable arrow-key navigation, false to disable it.
    • getOrient

      public String getOrient()
      Returns the orientation along which the slides advance.

      Default: "horizontal".

      Since:
      11.0.0
    • setOrient

      public void setOrient(String orient) throws WrongValueException
      Sets the orientation along which the slides advance.
      Parameters:
      orient - one of "horizontal" or "vertical"; a null value is treated as "horizontal".
      Throws:
      WrongValueException - if orient is neither "horizontal" nor "vertical".
    • getEffect

      public String getEffect()
      Returns the transition effect used when moving between slides.

      Default: "slide".

      Since:
      11.0.0
    • setEffect

      public void setEffect(String effect) throws WrongValueException
      Sets the transition effect used when moving between slides.
      Parameters:
      effect - one of "slide", "fade" or "none"; a null value is treated as "slide".
      Throws:
      WrongValueException - if effect is none of "slide", "fade" or "none".
    • getZclass

      public String getZclass()
      Description copied from class: HtmlBasedComponent
      Returns the ZK Cascading Style class for this component. It usually depends on the implementation of the mold (AbstractComponent.getMold()).

      Default: null (the default value depends on element).

      HtmlBasedComponent.setZclass(java.lang.String)) will completely replace the default style of a component. In other words, the default style of a component is associated with the default value of HtmlBasedComponent.getZclass(). Once it is changed, the default style won't be applied at all. If you want to perform small adjustments, use HtmlBasedComponent.setSclass(java.lang.String) instead.

      Overrides:
      getZclass in class HtmlBasedComponent
      See Also:
    • renderProperties

      protected void renderProperties(ContentRenderer renderer) throws IOException
      Description copied from class: HtmlBasedComponent
      Renders the content of this component, excluding the enclosing tags and children.

      See also ZK Client-side Reference: Property Rendering

      Overrides:
      renderProperties in class XulElement
      Throws:
      IOException
    • beforeChildAdded

      public void beforeChildAdded(Component child, Component refChild)
      Description copied from class: AbstractComponent
      Default: does nothing.
      Specified by:
      beforeChildAdded in interface ComponentCtrl
      Overrides:
      beforeChildAdded in class AbstractComponent
      Parameters:
      child - the child to be added (never null).
      refChild - another child component that the new child will be inserted before it. If null, the new child will be the last child.
      See Also:
    • onChildAdded

      public void onChildAdded(Component child)
      Description copied from class: AbstractComponent
      Default: handles special event listeners.
      Specified by:
      onChildAdded in interface ComponentCtrl
      Overrides:
      onChildAdded in class AbstractComponent
      See Also:
    • onChildRemoved

      public void onChildRemoved(Component child)
      Description copied from class: AbstractComponent
      Default: handles special event listeners.
      Specified by:
      onChildRemoved in interface ComponentCtrl
      Overrides:
      onChildRemoved in class AbstractComponent
      See Also:
    • service

      public void service(AuRequest request, boolean everError)
      Description copied from class: HtmlBasedComponent
      Processes an AU request.

      Default: it handles onClick, onDoubleClick, onRightClick onMove, onSize, onZIndex.

      Specified by:
      service in interface ComponentCtrl
      Overrides:
      service in class HtmlBasedComponent
      everError - whether any error ever occurred before processing this request.
      See Also:
    • getSelectedItem

      public Carouselitem getSelectedItem()
      Returns the currently active item, or null when there are no slides.

      The lookup uses the same clamped index as getActiveIndex() so the two getters stay in agreement when _activeIndex was set out of range before any child was attached.