Class PageIndicator

java.lang.Object
com.codename1.ui.Component
com.codename1.components.PageIndicator
All Implemented Interfaces:
Animation, Editable, StyleListener

public class PageIndicator extends Component

A row of page dots (a dots indicator or pager indicator) that shows which page of a pager, carousel or onboarding flow is on screen. The current page is drawn as a wider pill; tapping a dot selects its page.

Carousel includes one. Use it on its own with swipeable Tabs:

Form form = new Form("Pages", new BorderLayout());
Tabs pages = new Tabs();
pages.hideTabs();
pages.addTab("", new Label("First page"));
pages.addTab("", new Label("Second page"));
PageIndicator dots = new PageIndicator();
dots.bind(pages);
form.add(BorderLayout.CENTER, pages).add(BorderLayout.SOUTH, dots);
form.show();

The dots are drawn in the foreground colour of the PageIndicator UIID, the current one at full opacity and the rest faded, so they suit light and dark themes without styling.

  • Constructor Details

    • PageIndicator

      public PageIndicator()
      An indicator with no pages; set the count with #setPageCount(int) or #bind(Tabs).
    • PageIndicator

      public PageIndicator(int pageCount)

      An indicator for a number of pages.

      Parameters
      • pageCount: how many pages there are
  • Method Details

    • initUnselectedStyle

      protected void initUnselectedStyle(Style unselectedStyle)
      Description copied from class: Component

      Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.

      Parameters
      • unselectedStyle: The unselected style.
      Overrides:
      initUnselectedStyle in class Component
    • bind

      public void bind(Tabs tabs)

      Keeps this indicator in step with swipeable tabs: the count follows the number of tabs when they change selection, a swipe moves the dot, and a tap on a dot slides to that tab.

      Parameters
      • tabs: the tabs to follow
    • getPageCount

      public int getPageCount()

      The number of dots.

      Returns

      the page count

    • setPageCount

      public void setPageCount(int pageCount)

      Sets the number of dots.

      Parameters
      • pageCount: how many pages there are
    • getCurrentPage

      public int getCurrentPage()

      The page drawn as current.

      Returns

      the zero based current page

    • setCurrentPage

      public void setCurrentPage(int currentPage)

      Sets the page drawn as current. Does not fire the action listeners; they hear only taps.

      Parameters
      • currentPage: the zero based page
    • addActionListener

      public void addActionListener(ActionListener l)

      Listens to taps that select a page; #getCurrentPage() holds the page tapped.

      Parameters
      • l: the listener
    • removeActionListener

      public void removeActionListener(ActionListener l)

      Stops a listener from hearing taps.

      Parameters
      • l: the listener
    • calcPreferredSize

      protected Dimension calcPreferredSize()
      Description copied from class: Component

      Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

      Returns

      the calculated preferred size based on component content

      Overrides:
      calcPreferredSize in class Component
    • paint

      public void paint(Graphics g)
      Description copied from class: Component

      This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

      Parameters
      • g: the component graphics
      Specified by:
      paint in interface Animation
      Overrides:
      paint in class Component
    • pointerReleased

      public void pointerReleased(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer released event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerReleased in class Component