본문 바로가기
GUI( JavaFX Scene Builder )/Layout

VBox

by pms93 2022. 8. 15.
package application;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class VBoxEx extends Application {

	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage primaryStage) throws Exception {
		Pane p1 = new Pane();
		Pane p2 = new Pane();
		Pane p3 = new Pane();

		// HBox는 prefHeifgt설정이 원하는데로 되지 않았다면
		// VBox는 반대로 prefWeight설정이 원하는데로 되지 않는다.
		p1.setPrefHeight(100);
		p2.setPrefHeight(100);
		p3.setPrefHeight(100);
		
		p1.setMaxWidth(120);
		p2.setMaxWidth(120);
		p3.setMaxWidth(120);
		
		p1.setStyle("-fx-background-color : #FF4848");
		p2.setStyle("-fx-background-color : #FFFF5A");
		p3.setStyle("-fx-background-color : #6BEC62");
		
		VBox vbox = new VBox();
		vbox.getChildren().addAll(p1, p2, p3);
		vbox.setAlignment(Pos.CENTER);
		
		primaryStage.setTitle("VBox");
		primaryStage.setScene(new Scene(vbox, 800, 800));
		primaryStage.show();
	}

}

'GUI( JavaFX Scene Builder ) > Layout' 카테고리의 다른 글

ImageView  (0) 2022.08.16
StackPane  (0) 2022.08.16
HBox  (0) 2022.08.15
AnchorPane  (0) 2022.08.15
GUI (예제) (BorderPane, FlowPane, GridPane)  (0) 2022.08.15