I have designed my fxml using scene builder. Pagination comes with 10 pages as default and in page number buttons. 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 :
<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).
The bottom line is that you should never assign a new object to a @FXML
-annotated reference.
Instead of
pagination = new Pagination(7, 0);
do
pagination.setPageCount(7);
pagination.setCurrentPageIndex(0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.