Class Paginator

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class Paginator extends Container

A row of page numbers with previous and next arrows, for moving through results a page at a time.

Paginator pages = new Paginator(20);
pages.addActionListener(e -> Log.p("Page " + (pages.getPage() + 1)));

Pages are counted from 0 in the API and shown from 1. The first and the last page are always shown, with the pages next to the current one; the gaps become an ellipsis. setCompact(true) shows "3 / 20" between the arrows instead, for narrow screens. The numbers use the UIIDs PaginatorItem and PaginatorSelected, the ellipsis PaginatorEllipsis and the arrows PaginatorArrow.

  • Constructor Details

    • Paginator

      public Paginator()
      A paginator of a single page.
    • Paginator

      public Paginator(int pageCount)

      A paginator of the given number of pages.

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

    • getPageCount

      public int getPageCount()
      The number of pages.
    • setPageCount

      public void setPageCount(int pageCount)

      Sets the number of pages; the current page moves back when it is past the last one.

      Parameters
      • pageCount: how many pages there are
    • getPage

      public int getPage()
      The current page, counted from 0.
    • setPage

      public void setPage(int page)

      Moves to a page without firing the listeners.

      Parameters
      • page: the page, from 0
    • isCompact

      public boolean isCompact()
      True when the paginator shows only arrows and "page / pages".
    • setCompact

      public void setCompact(boolean compact)

      Shows only the arrows and "page / pages" instead of page numbers.

      Parameters
      • compact: true for the short form
    • setSiblingCount

      public void setSiblingCount(int count)

      Sets how many pages on each side of the current one are shown as numbers; 1 by default.

      Parameters
      • count: the pages on each side
    • addActionListener

      public void addActionListener(ActionListener l)

      Adds a listener told when the user moves to another page.

      Parameters
      • l: the listener
    • removeActionListener

      public void removeActionListener(ActionListener l)

      Removes a listener.

      Parameters
      • l: the listener
    • selectPage

      public void selectPage(int p)

      Moves to a page as if the user picked it, firing the listeners when the page changes.

      Parameters
      • p: the page, from 0
    • pageItems

      public static int[] pageItems(int page, int count, int siblings)

      The pages shown as numbers for a position, in order, with -1 for each ellipsis.

      Parameters
      • page: the current page, from 0
      • count: the number of pages
      • siblings: the pages shown on each side of the current one
      Returns

      the page indexes, -1 marking a gap