GUI( JavaFX Scene Builder )/Layout
HBox
by pms93
2022. 8. 15.
package application;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class HBoxEx extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Pane p1 = new Pane(), p2 = new Pane(), p3 = new Pane();
p1.setStyle("-fx-background-color : red");
p2.setStyle("-fx-background-color : yellow");
p3.setStyle("-fx-background-color : green");
// 각 Pane을 prefsize, prefHeight로 크기 설정을 해본 결과
// 원하는 크기로 설정되는것이 아닌 FlowPane처럼 최대치의 공간을 차지 한 후 창 크기의 변경에 따라 함께 반응한다.
// 왜
p1.setMaxHeight(100);
p2.setMaxHeight(100);
p3.setMaxHeight(100);
p1.setPrefWidth(120);
p2.setPrefWidth(120);
p3.setPrefWidth(120);
HBox hbox = new HBox();
hbox.getChildren().addAll(p1, p2, p3);
hbox.setAlignment(Pos.CENTER);
primaryStage.setScene(new Scene(hbox, 500, 250));
primaryStage.show();
}
}