我在學習javafx,並且用vbox佈局管理器做了很少的嘗試。代碼似乎是好的,但我想檢查,如果我真的明白它是如何工作的。Javafx:使用佈局管理器進行測試?
下面是代碼:
public class TestShape2 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Group root = new Group();
Label topLabel = new Label("Top...");
Label topLabel2 = new Label("Top 2...");
Rectangle rect = new Rectangle();
rect.setFill(Color.AQUA);
Label bottomLabel = new Label("Bottom...");
VBox vBox = new VBox();
rect.widthProperty().bind(vBox.widthProperty());
rect.heightProperty().bind(vBox.heightProperty());
vBox.getChildren().addAll(topLabel, topLabel2, rect, bottomLabel);
/*
* Code 1
*/
root.getChildren().add(vBox);
Scene scene = new Scene(root, 300, 300, Color.BLANCHEDALMOND);
/*
* Code 2
*/
// Scene scene = new Scene (vBox, 300, 300, Color.BLANCHEDALMOND);
primaryStage.setScene(scene);
primaryStage.show();
}
}
在「代碼1」:不垂直框中的寬度和高度是那些包含在根屁股的元件的根組是VBOX的父?那麼,vBox不會佔滿整個空間? 在「代碼2」中:因爲我不使用某個根組,因爲場景是vbox的父級,所以vbox的維度將是場景的維度? 我的理解是否正確?
如果這是正確的,我的問題是:將有一個「頂部標籤」,「底部標籤」和矩形,將填補所有的自由空間的代碼是什麼?在代碼2中,我從來沒有看到底部標籤「,因爲它看起來矩形的高度是場景的高度,所以我認爲底部的標籤不在場景中,但是如何解決這個問題?
謝謝大家在理解的JavaFX你的幫助