我使用场景生成器设计了我的 fxml。分页默认为 10 页,并带有页码按钮。我想根据我的场景更改这些默认内容。
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 :
<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" />
....
但是当我运行应用程序时我仍然得到默认配置。我的代码有什么问题吗?提前致谢....
最佳答案
您正在创建一个新的分页
,然后对其进行配置,而不是配置您在 FXML 中定义的分页(即显示在 UI 中的分页)。
最重要的是,您永远不应该将新对象分配给 @FXML
带注释的引用。
而不是
pagination = new Pagination(7, 0);
做
pagination.setPageCount(7);
pagination.setCurrentPageIndex(0);
关于注入(inject)到我的 Controller 类的 JavaFx @FXML Pagination 无法修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33336555/