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

GUI (예제) (BorderPane, FlowPane, GridPane)

by pms93 2022. 8. 15.
package total;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class prac extends Application {

	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage primaryStage) throws Exception {
		BorderPane bp = new BorderPane();
		
		// 상단
		FlowPane top = new FlowPane();
		top.setStyle("-fx-background-color : pink");
		top.getChildren().addAll(new Label("메뉴"), new Label("홈"), new Label("로그인"));
		top.setAlignment(Pos.CENTER);
		top.setPrefHeight(45);
		top.setHgap(90);
		bp.setTop(top);
		
		
		// 중단(좌) #00C6ED
		GridPane left = new GridPane();
		left.setStyle("-fx-background-color : #00C6ED");
		left.getChildren().add(new Button("메뉴 나열"));
		bp.setLeft(left);
		
		
		// 중단(중) #41FF3A
		GridPane center = new GridPane();
		center.setStyle("-fx-background-color : #41FF3A");
		center.getChildren().add(new Button("내용 들어가는 곳"));
		bp.setCenter(center);
		
		
		// 중단(우) #FFFFD2
		GridPane right = new GridPane();
		Button inputId = new Button("아이디 입력");
		inputId.setPrefSize(120, 30);
		Button inputPw = new Button("비밀번호 입력");
		inputPw.setPrefSize(120, 30);
		Button login = new Button("로그인");
		login.setPrefSize(110, 60);
		
		right.setStyle("-fx-background-color : #FFFFD2");
		right.add(inputId, 0, 0);
		right.add(inputPw, 0, 1);
		right.add(login, 1, 0, 1, 2);
		right.setPadding(new Insets(20));
		bp.setRight(right);
		
		
		// 하단 #DB9D7A
		FlowPane bottom = new FlowPane();
		bottom.setStyle("-fx-background-color : #DB9D7A");
		bottom.getChildren().add(new Button("바닥글 들어가는 곳"));
		bottom.setAlignment(Pos.CENTER);
		bottom.setPrefHeight(50);
		bp.setBottom(bottom);
		
		primaryStage.setScene(new Scene(bp, 500, 250));
		primaryStage.show();
	}

}

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

VBox  (0) 2022.08.15
HBox  (0) 2022.08.15
AnchorPane  (0) 2022.08.15
GUI (2)  (0) 2022.08.11
GUI (1)  (0) 2022.08.11