FXML
FXML์ JavaFX ์ ํ๋ฆฌ์ผ์ด์
์ ์ฌ์ฉ์ ์ธํฐํ์ด์ค๋ฅผ ์ ์ํ๋ XML ๊ธฐ๋ฐ์ ๋งํฌ์
์ธ์ด์
๋๋ค.
XML(eXtensible Markup Language)
๋ฐ์ดํฐ๋ฅผ ์ ์ก ์์ ๋๋ ์ฌ์ฉ์ ํ์ฅ ํ๊ทธ๋ฅผ ์ํ ๋งํฌ์
์ธ์ด์
๋๋ค.
ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ์ ๊ตฌ์กฐ๋ฅผ ์ ์ํ๋ฉฐ, ์ฌ์ฉ์๊ฐ ์ง์ ํ๊ทธ๋ฅผ ๋ง๋ค ์ ์์ด ํ์ฅ์ฑ์ด ๋ฐ์ด๋ฉ๋๋ค. ์น ์๋น์ค, ๋ฐ์ดํฐ ๊ตํ, ์ค์ ํ์ผ ๋ฑ ๋ค์ํ ์ฉ๋๋ก ํ์ฉ๋ฉ๋๋ค.
ํต์ฌ ์์
์์ | ์ค๋ช
|
AnchorPane | ๊ณ ์ ๋ ์์น์ UI ์์ ๋ฐฐ์น |
BorderPane | ์, ํ, ์ข, ์ฐ, ์ค์ 5๊ฐ ์์ญ์ผ๋ก UI ๋ฐฐ์น |
VBox | ์ธ๋ก ๋ฐฉํฅ์ผ๋ก UI ์์ ์ ๋ ฌ |
HBox | ๊ฐ๋ก ๋ฐฉํฅ์ผ๋ก UI ์์ ์ ๋ ฌ |
GridPane | ํ๊ณผ ์ด์ ๊ฒฉ์ ํํ๋ก UI ๋ฐฐ์น |
StackPane | ์ฌ๋ฌ ์ปดํฌ๋ํธ๋ฅผ ๊ฒน์ณ์ ๋ฐฐ์น |
TextField | ํ ์ค ํ
์คํธ ์
๋ ฅ ํ๋ |
PasswordField | ๋น๋ฐ๋ฒํธ ์
๋ ฅ ํ๋ |
Button | ๋ฒํผ ์์ฑ |
Label | ํ
์คํธ ๋ผ๋ฒจ ํ์ |
TableView | ํ
์ด๋ธ ํ์์ ๋ฐ์ดํฐ ํ์ |
ListView | ๋ฆฌ์คํธ ํํ๋ก ๋ฐ์ดํฐ ํ์ |
ImageView | ์ด๋ฏธ์ง ์ถ๋ ฅ |
MenuBar | ๋ฉ๋ด๋ฐ ์ถ๊ฐ |
๋ฌธ๋ฒ ์ฌํญ
๋ฌธ๋ฒ ์์ | ์ค๋ช
| ์์ |
XML ์ ์ธ | FXML ํ์ผ์ ์์ | <?xml version="1.0" encoding="UTF-8"?> |
๋ฃจํธ ์ปจํ
์ด๋ | UI์ ์ต์์ ์์ | <VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> |
์์ฑ ์ง์ | ์์์ ์์ฑ ์ค์ | <Button text="ํด๋ฆญ"/> |
์ด๋ฒคํธ ํธ๋ค๋ฌ | ์ปจํธ๋กค์ ์ด๋ฒคํธ ์ค์ | <Button onAction="#handleClick"/> |
์ปจํธ๋กค ID | FXML ์ปจํธ๋กค์ Java์์ ์ฐธ์กฐ ๊ฐ๋ฅํ๊ฒ ์ค์ | <TextField fx:id="usernameField"/> |
include ํ๊ทธ | ๋ค๋ฅธ FXML ํ์ผ ํฌํจ | <fx:include source="header.fxml"/> |
๊ณตํต ์์ฑ
์์ฑ | ์ค๋ช
| ์์ |
fx:id | ์ปจํธ๋กค์ Java ์ฝ๋์์ ์ ๊ทผํ ์ ์๋๋ก ์ค์ | <Button fx:id="submitButton"/> |
text | ๋ฒํผ์ด๋ ๋ผ๋ฒจ ๋ฑ์ ํ
์คํธ ์ค์ | <Label text="Hello, JavaFX!"/> |
onAction | ๋ฒํผ ํด๋ฆญ ๋ฑ์ ์ด๋ฒคํธ ์ค์ | <Button onAction="#handleClick"/> |
alignment | ์ ๋ ฌ ๋ฐฉ์ ์ค์ | <VBox alignment="CENTER"/> |
spacing | ์์ ์์ ๊ฐ๊ฒฉ | <VBox spacing="10"/> |
padding | ์ปจํ
์ด๋ ๋ด๋ถ ์ฌ๋ฐฑ ์ค์ | <VBox padding="10"/> |
์์ ์ฝ๋
(1) ๋ก๊ทธ์ธ ํ๋ฉด (login.fxml)
<?xml version="1.0" encoding="UTF-8"?>
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
alignment="CENTER" spacing="10">
<Label text="๋ก๊ทธ์ธ"/>
<TextField fx:id="usernameField" promptText="์์ด๋"/>
<PasswordField fx:id="passwordField" promptText="๋น๋ฐ๋ฒํธ"/>
<Button text="๋ก๊ทธ์ธ" onAction="#handleLogin"/>
</VBox>
XML
๋ณต์ฌ
(2) ํ์๊ฐ์ ํ๋ฉด (register.fxml)
<?xml version="1.0" encoding="UTF-8"?>
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
alignment="CENTER" spacing="10">
<Label text="ํ์๊ฐ์
"/>
<TextField fx:id="nameField" promptText="์ด๋ฆ"/>
<TextField fx:id="emailField" promptText="์ด๋ฉ์ผ"/>
<PasswordField fx:id="passwordField" promptText="๋น๋ฐ๋ฒํธ"/>
<Button text="๊ฐ์
ํ๊ธฐ" onAction="#handleRegister"/>
</VBox>
XML
๋ณต์ฌ
(3) ์์ด์ฝ ๋ฒํผ ๊ทธ๋ฆฌ๋ ๋งํฌ ํ๋ฉด (icon_grid.fxml)
<?xml version="1.0" encoding="UTF-8"?>
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
hgap="10" vgap="10" alignment="CENTER">
<Button text="ํ" GridPane.rowIndex="0" GridPane.columnIndex="0"/>
<Button text="์ค์ " GridPane.rowIndex="0" GridPane.columnIndex="1"/>
<Button text="ํ๋กํ" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
<Button text="๋ก๊ทธ์์" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
</GridPane>
XML
๋ณต์ฌ
(4) ๊ฒ์ํ ๋ชฉ๋ก ํ๋ฉด (board.fxml)
<?xml version="1.0" encoding="UTF-8"?>
<BorderPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<top>
<Label text="๊ฒ์ํ ๋ชฉ๋ก" style="-fx-font-size: 16px;"/>
</top>
<center>
<TableView fx:id="boardTable">
<columns>
<TableColumn text="๋ฒํธ" fx:id="colId"/>
<TableColumn text="์ ๋ชฉ" fx:id="colTitle"/>
<TableColumn text="์์ฑ์" fx:id="colAuthor"/>
<TableColumn text="๋ ์ง" fx:id="colDate"/>
</columns>
</TableView>
</center>
<bottom>
<HBox alignment="CENTER" spacing="10">
<Button text="์ ๊ธ ์์ฑ" onAction="#handleNewPost"/>
</HBox>
</bottom>
</BorderPane>
XML
๋ณต์ฌ



