如何使用 JavaFX 建立分頁?


分頁將內容分成多頁,並允許使用者跳到不同頁面或按順序瀏覽內容。可以透過例項化 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) {
      //Creating a pagination
      Pagination pagination = new Pagination();
      //Setting number of pages
      pagination.setPageCount(10);
      //Creating a vbox to hold the pagination
      VBox vbox = new VBox();
      vbox.setSpacing(5);
      vbox.setPadding(new Insets(50, 50, 50, 60));
      vbox.getChildren().addAll(pagination);
      //Setting the stage
      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);
   }
}

輸出

更新時間:2020 年 5 月 18 日

414 次瀏覽

開啟你的職業生涯

完成本課程獲得認證

開始
廣告