Tuesday, April 2, 2013

JavaFX Pagination

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

Example:
JavaFX Pagination
JavaFX Pagination


package javafx_pagination;

import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Pagination;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;

/**
* @web http://java-buddy.blogspot.com/
*/
public class JavaFX_Pagination extends Application {

private Pagination pagination;
final static int numOfPage = 5;

public VBox createPage(int pageIndex) {
VBox pageBox = new VBox();
Label pageLabel = new Label("Page " + (pageIndex+1));
pageBox.getChildren().add(pageLabel);
return pageBox;
}

@Override
public void start(Stage primaryStage) {

pagination = new Pagination(numOfPage);
pagination.setPageFactory(new Callback<Integer, Node>() {
@Override
public Node call(Integer pageIndex) {
return createPage(pageIndex);
}
});

AnchorPane anchor = new AnchorPane();
AnchorPane.setTopAnchor(pagination, 10.0);
AnchorPane.setRightAnchor(pagination, 10.0);
AnchorPane.setBottomAnchor(pagination, 10.0);
AnchorPane.setLeftAnchor(pagination, 10.0);
anchor.getChildren().add(pagination);

Scene scene = new Scene(anchor, 400, 300);

primaryStage.setTitle("java-buddy.blogspot.com");
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}
}


Next:
- Display images on JavaFX Pagination Control


No comments:

Post a Comment