簡體   English   中英

注入到我的控制器類的JavaFx @FXML分頁無法修改

[英]JavaFx @FXML Pagination injected to my controller class can't be modified

我已經使用場景生成器設計了fxml。 分頁默認為10頁,並在頁碼按鈕中。 我想根據自己的情況更改那些默認的東西。

這是我在控制器中所做的事情:

  @FXML
    private Pagination pagination;
    ...


    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        pagination = new Pagination(7, 0);
        pagination.setPageFactory((Integer pageIndex)->createUserInfo(pageIndex));
        pagination.getStyleClass().add(Pagination.STYLE_CLASS_BULLET);

    }
    ...

private VBox createUserInfo(int pageIndex) {
    VBox box = new VBox();
    ImageView iv = new ImageView(images[pageIndex]);
    box.setAlignment(Pos.CENTER);
    Label desc = new Label("PAGE Number");
    box.getChildren().addAll(iv, desc);
    return box;
}

這是我的FXML:

<StackPane fx:id="stackPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="538.0" prefWidth="747.0" style="-fx-background-color: #e8eaf6;" stylesheets="@../styles/inventory_fxml.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.inventory.controller.UserMange_fxmlController">
   <children>
      <Group nodeOrientation="LEFT_TO_RIGHT">
         <children>
            <VBox fx:id="vbox" prefHeight="483.0" prefWidth="685.0">
               <children>
                  <Pagination fx:id="pagination" prefHeight="352.0" prefWidth="685.0" stylesheets="@../styles/inventory_fxml.css" />

                 ....

但是在運行應用程序時,我仍然獲得默認配置。 我的代碼有什么問題嗎? 提前致謝....

您正在創建一個新的Pagination ,然后對其進行配置,而不是配置您在FXML中定義的Pagination (即,在UI中顯示的Pagination )。

最重要的是,您永遠不要將新對象分配給@FXML引用。

代替

pagination = new Pagination(7, 0);

pagination.setPageCount(7);
pagination.setCurrentPageIndex(0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM