HBox → 水平布局
Button b1 = new Button("button1");
Button b2 = new Button("button2");
Button b3 = new Button("button3");
AnchorPane ap = new AnchorPane();
ap.setStyle("-fx-background-color: #AEEEEE");
HBox box = new HBox();
box.setPrefWidth(400);
box.setPrefHeight(400);
box.getChildren().addAll(b1,b2,b3);
box.setStyle("-fx-background-color: #E066FF");
ap.getChildren().add(box);
HBox 類添加的按鈕都是水平排列的,如下圖
hbox_button
設(shè)置所有子組件的內(nèi)邊距,設(shè)置所有子組件的間距
box.setPadding(new Insets(10));//設(shè)置所有子組件內(nèi)邊距為10px
box.setSpacing(10);//設(shè)置所有子組件的間距(空間)
HBox
設(shè)置單個(gè)子組件b1的外邊距
box.setMargin(b1,new Insets(10));//設(shè)置單個(gè)子組件b1的外邊距
HBox
設(shè)置所有/某個(gè)組件的對齊方式
box.setAlignment(Pos.BOTTOM_CENTER);//設(shè)置所有組件的對齊方式,底居中
box.setAlignment(b,Pos.BOTTOM_CENTER);//設(shè)置某個(gè)組件的對齊方式,底居中
VBox → 垂直布局
VBox 類添加的按鈕都是垂直排列的,如下圖
AnchorPane ap = new AnchorPane();
ap.setStyle("-fx-background-color: #AEEEEE");
VBox box = new VBox();
Button b1 = new Button("button1");
Button b2 = new Button("button2");
Button b3 = new Button("button3");
box.setPrefWidth(400);
box.setPrefHeight(400);
box.getChildren().addAll(b1,b2,b3);
box.setStyle("-fx-background-color: #E066FF");
ap.getChildren().add(box);
vbox_button