下面列出了怎么用javafx.scene.control.Pagination的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void start(final Stage stage) throws Exception {
fonts = Font.getFamilies().toArray(fonts);
pagination = new Pagination(fonts.length / itemsPerPage(), 0);
pagination.getStyleClass().add(Pagination.STYLE_CLASS_BULLET);
pagination.setPageFactory((Integer pageIndex) -> 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().addAll(pagination);
Scene scene = new Scene(anchor);
stage.setScene(scene);
stage.setTitle("PaginationSample");
scene.getStylesheets().add("paginationsample/ControlStyle.css");
stage.show();
}
@Override
public void initializeParts() {
pagination = new Pagination();
pagination.getStyleClass().add("patient-pagination");
pagination.getStyleClass().add(Pagination.STYLE_CLASS_BULLET);
pagination.pageCountProperty().bind(Bindings.size(cabinet.getAllPatients()));
pagination.setPageFactory(
param -> new PatientView(cabinet.getAllPatients().get(param), translator));
}
/**
* {@inheritDoc}
*/
@Override
public final void layoutParts() {
getStyleClass().add(Pagination.STYLE_CLASS_BULLET);
}
public AnchorPane loadPresets(FlowPane base) {
File dir = new File("Presets");
File[] selectedFiles = dir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
if (pathname.getName().endsWith(".gofb")){
presetCount++;
return true;}
return false;
}
});
int pr = 0;
presets = new String[presetCount];
for (File selectedFile : selectedFiles) {
presets[pr] = selectedFile.getName().substring(0, selectedFile.getName().length() - 5);
pr++;
}
Pagination presetsPagination = new Pagination(presets.length, 0);
//pagination.setStyle("-fx-border-color:red;");
presetsPagination.setPageFactory(new Callback<Integer, Node>() {
@Override
public Node call(Integer pageIndex) {
if (pageIndex >= presets.length) {
return null;
} else {
return createPresetPage(pageIndex, base);
}
}
});
AnchorPane anchor = new AnchorPane();
AnchorPane.setTopAnchor(presetsPagination, 10.0);
AnchorPane.setRightAnchor(presetsPagination, 10.0);
AnchorPane.setBottomAnchor(presetsPagination, 10.0);
AnchorPane.setLeftAnchor(presetsPagination, 10.0);
anchor.getChildren().addAll(presetsPagination);
return anchor;
}