JAVA fx - JAVA fx 컨테이너 - StackPane (2022-08-15)

2022. 8. 16. 01:073층 1구역 - 개발의 장/JAVAfx - GUI

1. 서론

StackPane에 대해 알아보도록 하자.

 

StackPane는 간단하게 말하자면 오브젝트와 오브젝트를 '겹치게' 해주는 컨테이너 문이다.

 

2. 본론

겹치는 거 외엔 뭐가 없기 때문에 바로 코드와 결과로 보도록 하자.

 

package layouts_0812;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class StackPaneEx1 extends Application{

	public static void main(String[] args) {
		launch(args);
		
		

	}

	@Override
	public void start(Stage primaryStage) throws Exception {
    	//직사각형을 만들때 사용
		Rectangle rec = new Rectangle(100, 100, Color.YELLOW);
		Label label = new Label("사각형 안에 텍스트");
		
		//두 개 이상의 레이블을 겹쳐써야 할 때
		StackPane stack = new StackPane();
		stack.getChildren().addAll(rec, label);
		
		primaryStage.setTitle("STACKPANE");
		primaryStage.setScene(new Scene(stack, 500, 250));
		primaryStage.show();
	}

}

 

결과는?

 

노란색 사각형 안에 텍스트가 새겨진 것을 볼 수 있다.