標準のダイアログが無いようなので作ってみた。
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);
こんなダイアログが出る。
ラベルをセンターに置く方法がよくわからなかった。今後の課題。
0 件のコメント:
コメントを投稿