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

HBox, VBox 병합 예제(1)

by pms93 2022. 8. 17.
package total;

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

public class Quiz1 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();
		Pane p4 = new Pane(), p5 = new Pane(), p6 = new Pane();
		
		p1.setStyle("-fx-background-color : red");
		p1.setPrefSize(100, 100);
		p2.setStyle("-fx-background-color : orange");
		p2.setPrefSize(100, 100);
		p3.setStyle("-fx-background-color : black");
		p3.setPrefSize(100, 100);
		
		p4.setStyle("-fx-background-color : red");
		p4.setPrefSize(100, 100);
		p5.setStyle("-fx-background-color : orange");
		p5.setPrefSize(100, 100);
		p6.setStyle("-fx-background-color : black");
		p6.setPrefSize(100, 100);
		
		
		HBox hbox1 = new HBox();
		hbox1.getChildren().addAll(p1, p2, p3);
		hbox1.setAlignment(Pos.CENTER);
		hbox1.setSpacing(10);
		
		HBox hbox2 = new HBox();
		hbox2.getChildren().addAll(p4, p5, p6);
		hbox2.setAlignment(Pos.CENTER);
		hbox2.setSpacing(10);
		
		VBox vbox = new VBox();
		vbox.getChildren().addAll(hbox1, hbox2);
		vbox.setAlignment(Pos.CENTER);
		vbox.setSpacing(20);
		
		primaryStage.setScene(new Scene(vbox, 800, 800));
		primaryStage.show();
	}
	
}

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

Layout(Container) 예제  (0) 2022.08.18
HBox, VBox 병합 예제(2)  (0) 2022.08.17
ImageView  (0) 2022.08.16
StackPane  (0) 2022.08.16
VBox  (0) 2022.08.15