scene builderでfxml
DESCRIPTION
Japan JavaFX User Group seminar on 2 Jul. 2012."Editing FXML w/ Scene Builder"TRANSCRIPT
public class Hello extends Application {
}
public static void main(String[] args) { launch(args); }
@Override public void start(Stage stage) {
}
// ルートコンテナ AnchorPane root = new AnchorPane(); // Scene Graph を生成し、ルートコンテナを貼る Scene scene = new Scene(root); stage.setScene(scene);
stage.show();
// Scene Graph を構築
AnchorPane root = new AnchorPane(); Scene scene = new Scene(root); stage.setScene(scene);
TableView<Person> table = new TableView<>(); root.getChildren().add(table);
HBox hbox = new HBox(); Label label = new Label("Label"); hbox.getChildren().add(label); TextField field = new TextField("TextField"); hbox.getChildren().add(field); Button button = new Button("button"); hbox.getChildren().add(button); root.getChildren().add(hbox);
AnchorPane root = new AnchorPane(); Scene scene = new Scene(root); stage.setScene(scene);
TableView<Person> table = new TableView<>(); root.getChildren().add(table);
HBox hbox = new HBox(); Label label = new Label("Label"); hbox.getChildren().add(label); TextField field = new TextField("TextField"); hbox.getChildren().add(field); Button button = new Button("button"); hbox.getChildren().add(button); root.getChildren().add(hbox);
<AnchorPane prefHeight="400.0" prefWidth="600.0"> <children> <HBox alignment="CENTER" prefHeight="50.0" prefWidth="572.0" spacing="20.0"> <children> <Label style="-fx-font-size: 24;" text="Label" /> <TextField style="-fx-font-size: 24;" text="TextField" /> <Button style="-fx-font-size: 24;" text="Load" /> </children> </HBox> <TableView prefHeight="302.0" prefWidth="572.0" /> </children></AnchorPane>
<AnchorPane prefHeight="400.0" prefWidth="600.0"> <children> <HBox alignment="CENTER" prefHeight="50.0" prefWidth="572.0" spacing="20.0"> <children> <Label style="-fx-font-size: 24;" text="Label" /> <TextField style="-fx-font-size: 24;" text="TextField" /> <Button style="-fx-font-size: 24;" text="Load" /> </children> </HBox> <TableView prefHeight="302.0" prefWidth="572.0" /> </children></AnchorPane>
<AnchorPane prefHeight="400.0" prefWidth="600.0"> <children> <HBox alignment="CENTER" prefHeight="50.0" prefWidth="572.0" spacing="20.0"> <children> <Label style="-fx-font-size: 24;" text="Label" /> <TextField style="-fx-font-size: 24;" text="TextField" /> <Button style="-fx-font-size: 24;" text="Load" /> </children> </HBox> <TableView prefHeight="302.0" prefWidth="572.0" /> </children></AnchorPane>
<AnchorPane prefHeight="400.0" prefWidth="600.0"> <children> <HBox alignment="CENTER" prefHeight="50.0" prefWidth="572.0" spacing="20.0"> <children> <Label style="-fx-font-size: 24;" text="Label" /> <TextField style="-fx-font-size: 24;" text="TextField" /> <Button style="-fx-font-size: 24;" text="Load" /> </children> </HBox> <TableView prefHeight="302.0" prefWidth="572.0" /> </children></AnchorPane>
AnchorPane pane = FXMLLoader.load( this.getClass().getResource("table.fxml"));
<AnchorPane xmlns:fx="http://javafx.com/fxml" fx:controller="contents.TableController"> <children> <HBox> <children> <Label /> <TextField fx:id="textfield" /> <Button onAction="#handleAction" /> </children> </HBox> <TableView fx:id="table" /> </children></AnchorPane>
<AnchorPane xmlns:fx="http://javafx.com/fxml" fx:controller="contents.TableController"> <children> <HBox> <children> <Label /> <TextField fx:id="textfield" /> <Button onAction="#handleAction" /> </children> </HBox> <TableView fx:id="table" /> </children></AnchorPane>
<AnchorPane xmlns:fx="http://javafx.com/fxml" fx:controller="contents.TableController"> <children> <HBox> <children> <Label /> <TextField fx:id="textfield" /> <Button onAction="#handleAction" /> </children> </HBox> <TableView fx:id="table" /> </children></AnchorPane>public class TableController implements Initializable {
@FXML private TextField textfield; @FXML private TableView table; @FXML public void handleAction(ActionEvent event) { // テーブルの更新 } @Override public void initialize(URL url, ResourceBundle rb) { // テーブルの初期化 } }
public class TableController implements Initializable { @FXML private TextField textfield; @FXML private TableView table; @FXML public void handleAction(ActionEvent event) { // テーブルの更新 } @Override public void initialize(URL url, ResourceBundle rb) { // テーブルの初期化 } }
Conclusion
FXML でシーングラフを簡単に
MVC (Presentation Model, MVVM)
Scene Builder: FXML Editor
UI 構築には便利
まだまだ足りない点いっぱい