7주차 - javaFX (4) BorderPane 응용

2022. 9. 7. 19:28Java/javaFX & Scene Builder

이번의 목표

01. BorderPane을 응용해보자.


이번에는 지난 시간에 공부했던 BorderPane의 다른 예제를 알아볼 것입니다.

 

01. java 코드
02. fxml 코드
03. 실행화면

 

01. java 코드

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

	@Override
	public void start(Stage primaryStage) throws Exception {
		FXMLLoader loader = new FXMLLoader(getClass().getResource("Ex4.fxml"));
		
		Parent form = loader.load();
		
		Scene scene = new Scene(form);
		primaryStage.setScene(scene);
		primaryStage.setTitle("Ex4");
		primaryStage.show();
	}
}

02. fxml 파일의 코드

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="507.0" prefWidth="778.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ex1.Ex4">
   <top>
      <HBox alignment="CENTER" prefHeight="62.0" prefWidth="778.0" spacing="80.0" BorderPane.alignment="CENTER">
         <children>
            <Label text="홈" />
            <Label text="사회" />
            <Label text="경제" />
            <Label text="국제" />
            <Label text="문화" />
         </children>
      </HBox>
   </top>
   <left>
      <VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" spacing="50.0" BorderPane.alignment="CENTER">
         <children>
            <Label text="카테고리" />
            <Label text="노트북/PC" />
            <Label text="자동차용품" />
            <Label text="휴대폰" />
            <Label text="캠핑/낚시" />
         </children>
      </VBox>
   </left>
   <center>
      <VBox prefHeight="368.0" prefWidth="171.0" spacing="10.0" BorderPane.alignment="CENTER">
         <children>
            <HBox prefHeight="24.0" prefWidth="266.0" spacing="20.0">
               <children>
                  <Label text="ID" />
                  <TextField prefHeight="23.0" prefWidth="143.0" />
               </children>
            </HBox>
            <HBox prefHeight="29.0" prefWidth="266.0" spacing="15.0">
               <children>
                  <Label text="PW" />
                  <TextField prefHeight="23.0" prefWidth="144.0" />
               </children>
            </HBox>
            <HBox prefHeight="25.0" prefWidth="200.0" spacing="10.0">
               <children>
                  <RadioButton fx:id="radio" mnemonicParsing="false" text="여">
                     <toggleGroup>
                        <ToggleGroup fx:id="genGroup" />
                     </toggleGroup></RadioButton>
                  <RadioButton fx:id="radio" mnemonicParsing="false" text="남" toggleGroup="$genGroup" />
               </children>
               <padding>
                  <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
               </padding>
            </HBox>
            <HBox prefHeight="44.0" prefWidth="266.0" spacing="10.0">
               <children>
                  <CheckBox mnemonicParsing="false" text="게임" />
                  <CheckBox mnemonicParsing="false" text="공부" />
               </children>
               <padding>
                  <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
               </padding>
            </HBox>
            <Label text="하고 싶은 말" />
            <TextArea prefHeight="100.0" prefWidth="234.0" wrapText="true" />
         </children>
         <padding>
            <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
         </padding>
      </VBox>
   </center>
   <right>
      <VBox prefHeight="407.0" prefWidth="355.0" BorderPane.alignment="CENTER">
         <children>
            <GridPane hgap="10.0" vgap="10.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>
                  <TextField prefHeight="25.0" GridPane.valignment="BOTTOM" />
                  <PasswordField prefHeight="25.0" GridPane.rowIndex="1" GridPane.valignment="TOP" />
                  <Button mnemonicParsing="false" prefHeight="60.0" prefWidth="80.0" text="로그인" GridPane.columnIndex="1" GridPane.rowSpan="2" />
               </children>
            </GridPane>
         </children>
         <padding>
            <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
         </padding>
      </VBox>
   </right>
</BorderPane>

03. 실행 화면