Java/javaFX & Scene Builder
7주차 - javaFX (2) BorderPane, FlowPane, GridPane
우젼
2022. 9. 7. 19:12
오늘의 목표
01.BorderPane을 이용하여 틀을 잡고 그 안에서 FlowPane, GridPane, HBox 등을 사용해서 만들어 보자.
public class Ex2 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Ex2.fxml"));
Parent form = loader.load();
Scene scene = new Scene(form);
primaryStage.setScene(scene);
primaryStage.setTitle("Quiz");
primaryStage.show();
}
}
아래는 fxml의 코드
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="344.0" prefWidth="721.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<top>
<HBox alignment="CENTER" prefHeight="68.0" prefWidth="808.0" spacing="100.0" style="-fx-background-color: #FFA7A7;" BorderPane.alignment="CENTER">
<children>
<Label text="메뉴" />
<Label text="홈" />
<Label text="로그인" />
</children>
</HBox>
</top>
<left>
<FlowPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #36FFFF;" BorderPane.alignment="CENTER">
<children>
<Button mnemonicParsing="false" text="메뉴 나열" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</FlowPane>
</left>
<center>
<FlowPane prefHeight="379.0" prefWidth="370.0" style="-fx-background-color: #53FF4C;" BorderPane.alignment="CENTER">
<children>
<Button mnemonicParsing="false" text="내용 들어가는 곳" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</FlowPane>
</center>
<bottom>
<FlowPane alignment="CENTER" prefHeight="71.0" prefWidth="808.0" style="-fx-background-color: #CFA636;" BorderPane.alignment="CENTER">
<children>
<Button mnemonicParsing="false" text="바닥글 들어가는 곳" />
</children></FlowPane>
</bottom>
<right>
<FlowPane prefHeight="379.0" prefWidth="254.0" style="-fx-background-color: #FFFFB3;" BorderPane.alignment="CENTER">
<children>
<GridPane prefHeight="63.0" prefWidth="200.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button mnemonicParsing="false" prefHeight="25.0" prefWidth="150.0" text="아이디 입력" />
<Button mnemonicParsing="false" prefHeight="25.0" prefWidth="150.0" text="비밀번호 입력" GridPane.rowIndex="1" />
<Button mnemonicParsing="false" prefHeight="50.0" prefWidth="93.0" text="로그인" GridPane.columnIndex="1" GridPane.rowSpan="2" />
</children>
</GridPane>
</children>
<padding>
<Insets bottom="30.0" left="30.0" right="30.0" top="30.0" />
</padding>
</FlowPane>
</right>
</BorderPane>
아래는 실행 화면