如何使用 JavaFX 创建分页?
javafxobject oriented programmingprogramming更新于 2026/1/7 11:24:17
分页将内容划分为页面,并允许用户在页面之间跳转或按顺序浏览内容。您可以通过实例化 javafx.scene.control.Pagination 类来创建分页。
示例
以下示例演示了如何创建 Pagination。
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Pagination;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class PaginationExample extends Application {
public void start(Stage stage) {
//创建分页
Pagination pagination = new Pagination();
//设置页数
pagination.setPageCount(10);
//创建 vbox 来保存分页
VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(50, 50, 50, 60));
vbox.getChildren().addAll(pagination);
//设置舞台
Group root = new Group(vbox);
Scene scene = new Scene(root, 595, 200, Color.BEIGE);
stage.setTitle("Pagination");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
输出


