JavaFxの情報は少なかったが、いろいろ調べて作成。
1.まず掌田津耶乃さんのサイトの「初心者のためのJavaFXプログラミング入門」の記事がとても参考になった。
さらに紀伊国屋で「JavaFX & Java 8プログラミング (著:日向 俊二、カットシステム刊)」も購入。
→Amazonリンク
2.基本的にはfxmlファイルというGUIレイアウト用XMLファイルとそれを読み込みウィンドウを表示するメインの
クラスとfxmlファイルのコントロールの初期化やイベント処理を記述したコントロールクラスで構成される
3.fxmlファイルサンプル
なんとfxmlファイル中に
fxmlサンプル(抜粋)
---------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<?import java.net.*?>
<?import java.net.URL ?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.collections.FXCollections?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="488.0" prefWidth="600.0"
styleClass="root" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="AppCtrl2">
<top>
<FlowPane orientation="VERTICAL" prefHeight="122.0" prefWidth="600.0" style="-fx-background-color: #ddddee;" BorderPane.alignment="CENTER">
<children>
<FlowPane prefHeight="36.0" prefWidth="600.0">
<children>
<Label fx:id="title" alignment="TOP_LEFT" prefHeight="37.0" prefWidth="395.0" style="-fx-padding: 0 0 0 10;" text="Cocktail Palette">
<font>
<Font name="Meiryo UI" size="24.0" />
</font>
</Label>
</children>
</FlowPane>
<Separator prefWidth="200.0" valignment="BOTTOM" />
<FlowPane id="searchNameBox" fx:id="searchNameBox" hgap="10.0" layoutX="10.0" layoutY="10.0" prefHeight="40.0" prefWidth="600.0"
style="-fx-padding: 5 0 0 20;">
<children>
<Label id="searchNameLabel" fx:id="searchNameLabel" text="名前で:" />
<TextField fx:id="searchNameText" prefHeight="23.0" prefWidth="300.0" />
<Button fx:id="searchNameBtn" mnemonicParsing="false" prefHeight="23.0" prefWidth="70.0" text="検索" />
</children>
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</FlowPane>
<FlowPane fx:id="searchMateBox" hgap="10.0" layoutX="10.0" layoutY="75.0" prefHeight="32.0" prefWidth="600.0" style="-fx-padding: 5 5 5 20;">
<children>
<Label id="searchMateLabel" fx:id="searchMateLabel" text="材料で:" />
<TextField fx:id="searchMateText" prefHeight="23.0" prefWidth="300.0" />
<Button fx:id="searchMateBtn" mnemonicParsing="false" prefHeight="23.0" prefWidth="70.0" text="検索" />
</children>
<FlowPane.margin>
<Insets />
</FlowPane.margin>
</FlowPane>
</children>
</FlowPane>
</top>
......続く
---------------------------------------------------------------------
4.fxmlファイルは最初は「JavaFX Scene Builder」というGUIデザインツールで簡単にマウスで作成できる。
しかしその後の修正は手書き。でもコンパイル前にGUIが確認できるので便利。