`VBox` doesn't put Node under `FlowPane`

Hello, my problem is than my VBox doesn't put next Node under my FlowPane. I'm adding nodes dynamicly to it and VBox put's next Node below FIRST line in FlowPane. Do you know what may cause that?👀
25 Replies
JavaBot
JavaBot•3y ago
Hey, @fertiz! Please remember to /close this post once your question has been answered!
stechy1
stechy1•3y ago
Hello, can you show some code?
fertiz
fertizOP•3y ago
sure
public final class CustomStat extends HBox {

public CustomStat(ImageView icon, String value, String tooltip) {
// #191B20 | #2C2F37
this.setStyle("-fx-background-color: #191B20; -fx-background-radius: 50");

this.setSpacing(15);

Text valueText = new Text(value);

valueText.setFont(Font.font("Arial", 20));

valueText.setStyle("-fx-fill: #45464b; -fx-font-family: Arial; -fx-font-size: 20;");

this.setAlignment(Pos.CENTER);

this.setPadding(new Insets(10, 10, 10, 10));

this.getChildren().addAll(icon, valueText);
}
}
public final class CustomStat extends HBox {

public CustomStat(ImageView icon, String value, String tooltip) {
// #191B20 | #2C2F37
this.setStyle("-fx-background-color: #191B20; -fx-background-radius: 50");

this.setSpacing(15);

Text valueText = new Text(value);

valueText.setFont(Font.font("Arial", 20));

valueText.setStyle("-fx-fill: #45464b; -fx-font-family: Arial; -fx-font-size: 20;");

this.setAlignment(Pos.CENTER);

this.setPadding(new Insets(10, 10, 10, 10));

this.getChildren().addAll(icon, valueText);
}
}
(^ This is what I add to FlowPane)
public final class CustomStatsPane extends FlowPane {

public CustomStatsPane() {
this.setPrefWidth(1280);
this.setOrientation(Orientation.HORIZONTAL);
this.setAlignment(Pos.TOP_CENTER);
this.setHgap(25);
this.setPrefWrapLength(Region.USE_COMPUTED_SIZE);
this.setVgap(25);
}

public void addStats(CustomStat... stats) {
this.getChildren().addAll(stats);
}
}
public final class CustomStatsPane extends FlowPane {

public CustomStatsPane() {
this.setPrefWidth(1280);
this.setOrientation(Orientation.HORIZONTAL);
this.setAlignment(Pos.TOP_CENTER);
this.setHgap(25);
this.setPrefWrapLength(Region.USE_COMPUTED_SIZE);
this.setVgap(25);
}

public void addStats(CustomStat... stats) {
this.getChildren().addAll(stats);
}
}
(^ this is FlowPane)
CustomStatsPane statsPane = new CustomStatsPane();

VBox.setVgrow(statsPane, Priority.ALWAYS);

for (int i = 0; i < 10; i++) {
ImageView test = new ImageView("assets/units/Bazooka.png");
test.setFitWidth(35);
test.setFitHeight(30);
CustomStat stat = new CustomStat(test, "test: " + user.getTimesAttacked(), "dd");
statsPane.addStats(stat);
}
CustomStatsPane statsPane = new CustomStatsPane();

VBox.setVgrow(statsPane, Priority.ALWAYS);

for (int i = 0; i < 10; i++) {
ImageView test = new ImageView("assets/units/Bazooka.png");
test.setFitWidth(35);
test.setFitHeight(30);
CustomStat stat = new CustomStat(test, "test: " + user.getTimesAttacked(), "dd");
statsPane.addStats(stat);
}
(^ this is how I use Flowpane)
fertiz
fertizOP•3y ago
No description
fertiz
fertizOP•3y ago
the parent is VBox with 50 spacing so I think somehow FlowPane height is just for 1 row. any clue?
stechy1
stechy1•3y ago
So issue is that red and yellow box overlaps?
fertiz
fertizOP•3y ago
yes that yellow box overlaps red one (red = FlowPane) but when I have just 1 row of FlowPane, everything is good it's like it doesnt count the second row
stechy1
stechy1•3y ago
huh, that seems like a bug in calculation of a height. What if you remove the priority for Vgrow? or isn't the issue that it does not fit into the total height?
fertiz
fertizOP•3y ago
I mean whenever I tried HBox#getWidth (from CustomStat) it returns 0, same goes for height and FlowPane
stechy1
stechy1•3y ago
getWidth is tricky. Try to use getPrefWidth/getPrefHeight from what I remember, the pref properties are properly updated
fertiz
fertizOP•3y ago
yes but VBox doesn't use getPrefWidth but getWidth same goes for height
stechy1
stechy1•3y ago
I see... 🤔
fertiz
fertizOP•3y ago
idk why it calculates only first row
stechy1
stechy1•3y ago
Unfortunately I'm not close to my computer so I can not try it... :/
fertiz
fertizOP•3y ago
my FlowPane is actually good, I rendered the border but idk why other pane overlaps it
stechy1
stechy1•3y ago
you can maybe try to call "requestLayout" on VBox manually...
fertiz
fertizOP•3y ago
still nothing
fertiz
fertizOP•3y ago
drawn borders
No description
stechy1
stechy1•3y ago
What version of JavaFX do you use? Have you tried latest version? Maybe it is fixed in some newer versions...
fertiz
fertizOP•3y ago
it is latest is there any other alternative for FlowPane :??
stechy1
stechy1•3y ago
Just to be sure... Well, I can not help now, but I will check it tomorrow when I will be on computer...
fertiz
fertizOP•3y ago
alright
stechy1
stechy1•3y ago
Nothing of what I know... Maybe some 3rd party lib
fertiz
fertizOP•3y ago
I think I got it working, all I had to do was flowPane.setMinHeight(flowPane.prefHeight(-1)); crazy
JavaBot
JavaBot•3y ago
Post Closed
This post has been closed by <@723844486974668810>.

Did you find this page helpful?