Код: Выделить всё
public class Test1 extends Application {
@Override
public void start(Stage primaryStage) {
Font systemFont = Font.font("System", 14);
VBox root = new VBox(
createBox("red", systemFont),
createBox("yellow", systemFont),
createBox("red", systemFont)
);
Scene scene = new Scene(root, 300, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
private HBox createBox(String color, Font font) {
var hBox = new HBox();
hBox.setStyle("-fx-padding: 0; -fx-background-color: " + color);
var text = new Text("Hello, World!");
text.setFont(font);
hBox.getChildren().add(text);
hBox.heightProperty().addListener((ov, oldV, newV) -> System.out.println("NewHeight:" + newV));
return hBox;
}
public static void main(String[] args) {
launch(args);
}
}
и это вывод:
и это
Код: Выделить всё
NewHeight:17.0
NewHeight:17.0
NewHeight:17.0
Подробнее здесь: https://stackoverflow.com/questions/796 ... -in-javafx