android:textIsSelectable="true"選択できるようになる。
標準のダイアログが無いようなので作ってみた。
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.control.*;
import javafx.event.*;
public class FBDialog {
private static final int W = 300;
private static final int H = 120;
private static final int BUTTON_W = 80;
public static void show(String title, String message, final Stage owner) {
final Stage stage = new Stage();
stage.setResizable(false);
stage.initModality(Modality.APPLICATION_MODAL);
stage.initOwner(owner);
stage.setTitle(title);
Group root = new Group();
Scene scene = new Scene(root, W, H, Color.WHITE);
Label label = new Label();
label.setText(message);
label.setLayoutX(10);
label.setLayoutY(20);
label.setMaxWidth(W-20);
label.setWrapText(true);
Button button = new Button();
button.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
stage.hide();
}
});
button.setPrefWidth(BUTTON_W);
button.setLayoutX(W / 2 - BUTTON_W / 2);
button.setLayoutY(80);
button.setText("OK");
root.getChildren().addAll(label, button);
stage.setScene(scene);
stage.show();
}
}
例えばこんなコードを書いて実行すると、
FBDialog.show("Test", "This is a test dialog.", stage);
こんなダイアログが出る。
ラベルをセンターに置く方法がよくわからなかった。今後の課題。
Java FXの実行ファイルを作るのに、ビルドファイルをどう書けばいいのか悩んでたけど、解決した。
こちらのサイトで紹介されていたコードを改造した。
JavaFX プロジェクトの実行可能 Jar ファイルを作成する with Apache Ant
jdk1.7になって以前とパスが変わったようなので、その辺も少し修正。環境変数はこんなかんじ。
JAVA_HOME C:\Program Files\Java\jdk1.7.0_07
で、build.xmlはこんなかんじ。
<project name="JavaFXProject" basedir="." default="pack" xmlns:fx="javafx:com.sun.javafx.tools.ant">
<property environment="env" />
<property name="javafx.tools.ant.jar" value="${env.JAVA_HOME}/lib/ant-javafx.jar" />
<property name="src" location="src/main/java" />
<property name="dest" location="build/classes/main" />
<property name="jardest" location="build/libs" />
<property name="app.vendor" value="com.fb" />
<property name="app.id" value="fxtest01" />
<property name="app.name" value="FXTest01" />
<property name="app.version" value="1.0" />
<property name="app.main-class" value="com.fb.fxtest.FXTest01" />
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant" classpath="${javafx.tools.ant.jar}"/>
<target name="clean">
<delete dir="build" />
</target>
<target name="compile" depends="clean">
<mkdir dir="${dest}" />
<javac srcdir="${src}" destdir="${dest}" classpath="${env.JAVA_HOME}/jre/lib/jfxrt.jar" />
<copy todir="${dest}">
<fileset dir="${src}" includes = "**/*.fxml" />
</copy>
</target>
<target name="pack" depends="compile">
<fx:application id="app-info" name="${app.name}" mainClass="${app.main-class}" />
<fx:jar destfile="${jardest}/${app.id}.jar">
<fx:application refid="app-info"/>
<manifest>
<attribute name="Implementation-Vendor" value="${app.vendor}"/>
<attribute name="Implementation-Title" value="${app.name}"/>
<attribute name="Implementation-Version" value="${app.version}"/>
</manifest>
<fileset dir="${dest}"/>
</fx:jar>
</target>
</project>
使用したサンプルデータはこちら。