答案 0 :(得分:4)
这是一个如何在FlowPane中使用VBox的示例。由于您没有发布Minimal, Reproducible Example但您知道了,所以它显然与您的不完全相同。
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
FlowPane flowPane = new FlowPane();
flowPane.setStyle("-fx-background-color: rgb(50, 50, 50)");
flowPane.setOrientation(Orientation.VERTICAL);
flowPane.setVgap(20);
flowPane.getChildren().add(new TextField("1"));
VBox gramsVBox = new VBox();
gramsVBox.setStyle("-fx-background-color: Blue; -fx-background-radius: 5 5 5 5;");
gramsVBox.getChildren().add(new Label("Grams:"));
gramsVBox.getChildren().add(new Label("453.000000001"));
VBox kiloGramsVBox = new VBox();
kiloGramsVBox.setStyle("-fx-background-color: Green; -fx-background-radius: 5 5 5 5;");
kiloGramsVBox.getChildren().add(new Label("KiloGrams:"));
kiloGramsVBox.getChildren().add(new Label(".453000000001"));
VBox ouncesVBox = new VBox();
ouncesVBox.setStyle("-fx-background-color: Red; -fx-background-radius: 5 5 5 5;");
ouncesVBox.getChildren().add(new Label("Ounces"));
ouncesVBox.getChildren().add(new Label("16"));
flowPane.getChildren().addAll(gramsVBox,kiloGramsVBox,ouncesVBox);
Stage stage = new Stage();
stage.setHeight(220);
stage.setScene(new Scene(flowPane));
stage.show();
}
}