简体   繁体   English

注入到我的控制器类的JavaFx @FXML分页无法修改

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

I have designed my fxml using scene builder. 我已经使用场景生成器设计了fxml。 Pagination comes with 10 pages as default and in page number buttons. 分页默认为10页,并在页码按钮中。 I want to change those default stuffs according to my scenario. 我想根据自己的情况更改那些默认的东西。

Here is what I have done in my controller: 这是我在控制器中所做的事情:

  @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;
}

Here is my FXML : 这是我的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" />

                 ....

But Still I get default configurations as I run the app. 但是在运行应用程序时,我仍然获得默认配置。 Is there anything wrong with my code ?? 我的代码有什么问题吗? Thanks in advance.... 提前致谢....

You are creating a new Pagination and then configuring it, instead of configuring the one you defined in the FXML (ie the one that is displayed in the UI). 您正在创建一个新的Pagination ,然后对其进行配置,而不是配置您在FXML中定义的Pagination (即,在UI中显示的Pagination )。

The bottom line is that you should never assign a new object to a @FXML -annotated reference. 最重要的是,您永远不要将新对象分配给@FXML引用。

Instead of 代替

pagination = new Pagination(7, 0);

do

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM