본문 바로가기
etc/JavaFX

[Java Fx] 컨테이너(Container)

by 겅아링 2020. 5. 31.
반응형

1. 무대와 장면

무대(Stage)는 윈도우 하나에 하나의 장면(Scene)만 가질 수 있다

 

 

2. 컨테이너

: 화면을 구성하는 UI 컨트롤러(객체) 를 쉽게 배치할 수 있도록 도와주는 클래스

컨테이너의 종류

AcnhorPane

: 컨트롤을 좌표로 배치하는 레이아웃

 

소스코드

public class AppMainTest extends Application {
			public static void main(String[] args) {
				launch(args);
			}

			@Override
			public void start(Stage arg0) throws Exception {
				VBox root = new VBox();
				root.setPrefHeight(150);
				root.setPrefWidth(300);
				root.setAlignment(Pos.CENTER);
				root.setSpacing(30);
				Label label = new Label();
				label.setText("안녕하세요");
				label.setFont(new Font(30.0));
				Button button = new Button();
				button.setOnAction(new EventHandler() {
					@Override
					public void handle(ActionEvent event) {
						Platform.exit();
					}
				});
				button.setText("종료");
				ObservableList list1 = root.getChildren();
				list1.add(label);
				list1.add(button);
				Scene s = new Scene(root);
				arg0.setScene(s);
				arg0.setTitle("KyungAh");
				arg0.show();
			}
		}

 

 

 

반응형

'etc > JavaFX' 카테고리의 다른 글

[Java Fx] FXML & Scene Builder  (0) 2020.05.30
[Java Fx] 시작하기  (0) 2020.05.29