[英]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.