Class Pagination

All Implemented Interfaces:
Styleable, EventTarget, Skinnable

@DefaultProperty("pages") public class Pagination extends Control

A Pagination control is used for navigation between pages of a single content, which has been divided into smaller parts.

Styling the page indicators

The control can be customized to display numeric page indicators or bullet style indicators by setting the style class STYLE_CLASS_BULLET. The maxPageIndicatorCountProperty can be used to change the maximum number of page indicators. The property value can also be changed via CSS using -fx-max-page-indicator-count. By default, page indicator numbering starts from 1 (corresponding to page index 0).

Page count

The pageCountProperty controls the number of pages this pagination control has. If the page count is not known, INDETERMINATE should be used as the page count.

Page factory

The pageFactoryProperty is a callback function that is called when a page has been selected by the application or the user. The function is required for the functionality of the pagination control. The callback function should load and return the contents of the selected page. null should be returned if the selected page index does not exist.

Creating a Pagination control:

A simple example of how to create a pagination control with ten pages and each page containing text.

 Pagination pagination = new Pagination(10, 0);
 pagination.setPageFactory(new Callback<Integer, Node>() {
     @Override
     public Node call(Integer pageIndex) {
         return new Label(pageIndex + 1 + ". Lorem ipsum dolor sit amet,\n"
                      + "consectetur adipiscing elit,\n"
                      + "sed do eiusmod tempor incididunt ut\n"
                      + "labore et dolore magna aliqua.");
     }
 });
or using lambdas
 Pagination pagination = new Pagination(10, 0);
 pagination.setPageFactory(pageIndex ->
         new Label(pageIndex + 1 + ". Lorem ipsum dolor sit amet,\n"
                      + "consectetur adipiscing elit,\n"
                      + "sed do eiusmod tempor incididunt ut\n"
                      + "labore et dolore magna aliqua.");
 );
Image of the Pagination control
Since:
JavaFX 2.2
  • Property Details

    • maxPageIndicatorCount

      public final IntegerProperty maxPageIndicatorCountProperty
      The maximum number of page indicators to use for this pagination control. The maximum number of pages indicators will remain unchanged if the value is less than 1 or greater than the pageCount. The number of page indicators will be reduced to fit the control if the maxPageIndicatorCount cannot fit. The default is 10 page indicators.
      See Also:
    • pageCount

      public final IntegerProperty pageCountProperty
      The number of pages for this pagination control. This value must be greater than or equal to 1. INDETERMINATE should be used as the page count if the total number of pages is unknown. The default is an INDETERMINATE number of pages.
      See Also:
    • currentPageIndex

      public final IntegerProperty currentPageIndexProperty
      The current page index to display for this pagination control. The first page will be the current page if the value is less than 0. Similarly the last page will be the current page if the value is greater than the pageCount The default is 0 for the first page.

      Because the page indicators set the current page index, the currentPageIndex property permits only bidirectional binding. The bind method throws an UnsupportedOperationException.

      See Also:
    • pageFactory

      public final ObjectProperty<Callback<Integer,Node>> pageFactoryProperty
      The pageFactory callback function that is called when a page has been selected by the application or the user. This function is required for the functionality of the pagination control. The callback function should load and return the contents the page index. Null should be returned if the page index does not exist. The currentPageIndex will not change when null is returned. The default is null if there is no page factory set.
      See Also:
  • Field Details

    • STYLE_CLASS_BULLET

      public static final String STYLE_CLASS_BULLET
      The style class to change the numeric page indicators to bullet indicators.
      See Also:
    • INDETERMINATE

      public static final int INDETERMINATE
      Value for indicating that the page count is indeterminate.
      See Also:
  • Constructor Details

    • Pagination

      public Pagination(int pageCount, int pageIndex)
      Constructs a new Pagination control with the specified page count and page index.
      Parameters:
      pageCount - the number of pages for the pagination control
      pageIndex - the index of the first page.
    • Pagination

      public Pagination(int pageCount)
      Constructs a new Pagination control with the specified page count.
      Parameters:
      pageCount - the number of pages for the pagination control
    • Pagination

      public Pagination()
      Constructs a Pagination control with an INDETERMINATE page count and a page index equal to zero.
  • Method Details

    • setMaxPageIndicatorCount

      public final void setMaxPageIndicatorCount(int value)
      Sets the maximum number of page indicators.
      Parameters:
      value - the number of page indicators. The default is 10.
    • getMaxPageIndicatorCount

      public final int getMaxPageIndicatorCount()
      Returns the maximum number of page indicators.
      Returns:
      the maximum number of page indicators
    • maxPageIndicatorCountProperty

      public final IntegerProperty maxPageIndicatorCountProperty()
      The maximum number of page indicators to use for this pagination control. The maximum number of pages indicators will remain unchanged if the value is less than 1 or greater than the pageCount. The number of page indicators will be reduced to fit the control if the maxPageIndicatorCount cannot fit. The default is 10 page indicators.
      See Also:
    • setPageCount

      public final void setPageCount(int value)
      Sets the number of pages.
      Parameters:
      value - the number of pages
    • getPageCount

      public final int getPageCount()
      Returns the number of pages.
      Returns:
      the number of pages
    • pageCountProperty

      public final IntegerProperty pageCountProperty()
      The number of pages for this pagination control. This value must be greater than or equal to 1. INDETERMINATE should be used as the page count if the total number of pages is unknown. The default is an INDETERMINATE number of pages.
      See Also:
    • setCurrentPageIndex

      public final void setCurrentPageIndex(int value)
      Sets the current page index.
      Parameters:
      value - the current page index.
    • getCurrentPageIndex

      public final int getCurrentPageIndex()
      Returns the current page index.
      Returns:
      the current page index
    • currentPageIndexProperty

      public final IntegerProperty currentPageIndexProperty()
      The current page index to display for this pagination control. The first page will be the current page if the value is less than 0. Similarly the last page will be the current page if the value is greater than the pageCount The default is 0 for the first page.

      Because the page indicators set the current page index, the currentPageIndex property permits only bidirectional binding. The bind method throws an UnsupportedOperationException.

      See Also:
    • setPageFactory

      public final void setPageFactory(Callback<Integer,Node> value)
      Sets the page factory callback function.
      Parameters:
      value - the page factory callback function
    • getPageFactory

      public final Callback<Integer,Node> getPageFactory()
      Returns the page factory callback function.
      Returns:
      the page factory callback function
    • pageFactoryProperty

      public final ObjectProperty<Callback<Integer,Node>> pageFactoryProperty()
      The pageFactory callback function that is called when a page has been selected by the application or the user. This function is required for the functionality of the pagination control. The callback function should load and return the contents the page index. Null should be returned if the page index does not exist. The currentPageIndex will not change when null is returned. The default is null if there is no page factory set.
      See Also:
    • getClassCssMetaData

      public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
      Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.
      Returns:
      the CssMetaData
      Since:
      JavaFX 8.0
    • getControlCssMetaData

      public List<CssMetaData<? extends Styleable,?>> getControlCssMetaData()
      Gets the unmodifiable list of the control's CSS-styleable properties.
      Overrides:
      getControlCssMetaData in class Control
      Returns:
      the unmodifiable list of the control's CSS-styleable properties
      Since:
      JavaFX 8.0