Reputation: 108
The java controller
public class MainContentController implements Initializable {
@FXML private ScrollPane scrollPane;
public void initialize(URL arg0, ResourceBundle arg1) {
Random r = new Random();
JFXMasonryPane masonryPane = new JFXMasonryPane();
scrollPane.setContent(masonryPane);
scrollPane.setFitToWidth(true);
for (int i = 0; i < 6000; i++) {
Label lbl = new Label(String.valueOf(i));
lbl.setAlignment(Pos.CENTER);
lbl.setPrefSize(r.nextInt(200), r.nextInt(200));
lbl.setStyle("-fx-background-color:rgb(" + r.nextInt(255) + "," + r.nextInt(255) + "," + r.nextInt(255) + ");");
masonryPane.getChildren().add(lbl);
}
}
}
And the FXML
<GridPane xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainContentController">
<rowConstraints>
<RowConstraints percentHeight="20.0" />
<RowConstraints percentHeight="20.0" />
<RowConstraints percentHeight="20.0" />
<RowConstraints percentHeight="20.0" />
<RowConstraints percentHeight="20.0" />
</rowConstraints>
<columnConstraints>
<ColumnConstraints percentWidth="25.0" />
<ColumnConstraints percentWidth="25.0" />
<ColumnConstraints percentWidth="25.0" />
<ColumnConstraints percentWidth="25.0" />
</columnConstraints>
<children>
<ScrollPane fx:id="scrollPane" GridPane.columnSpan="4" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.rowSpan="3" GridPane.valignment="CENTER"/>
</children>
</GridPane>
Tried to use the simplest example I can to show what I mean. When you execute this code, it generates 6000 randomly sized/colored blocks like it's supposed to. However, the amount possible to see depends on the width of your window, and it adjusts as you change it. Theoretically, this should display all 6000 blocks and you just have to scroll farther down if your window is narrower, which is my intent/goal. However, at some seemingly uneventful height it just cuts off anything that would be below it. I cannot find any setting or method that has had any effect on this.
Using JFXMasonryPane by JFoenix. However, I'm not sure if this is an issue with their library or with my utilization of ScrollPane.
Upvotes: 2
Views: 540
Reputation: 49241
This is caused because the number of rows in the masonry pane is limited to 100 (which is also the default value). I don't think you can change that behavior because the limitation is hard-coded, see e.g. https://github.com/jfoenixadmin/JFoenix/issues/302. You can use the setLimitRow-method to change the value but all values larger than 100 are ignored and the default/maximum-value 100 is used.
In your example the number of labels is 6000. The number of rows is 100 (default/maximum as stated before). Assuming that a large window can contain 25 columns the number of labels in the masonry pane is 100 * 25 = 2500. Thus, 6000 - 2500 = 3500 of the labels are not displayable. Decreasing the width of the window reduces the number of the columns and thus the number of the labels.
The problem will always occur if more than 100 childs/labels are involved. At the latest in the case of one column not all labels are displayed.
For the illustration I use your code snippet but with equal square labels for the sake of simplicity. The following two screenshots (beginning and end) show the 100 * 25 = 2500 labels for a window with 25 columns (6000 - 2500 = 3500 labels are not displayed):
Beginning:
End:
The next two screenshots (beginning and end) show the 100 * 1 = 100 labels for a window with 1 column (6000 - 100 = 5900 labels are not displayed):
Beginning and End:
Upvotes: 1