JavaFX 佈局 DialogPane

DialogPane

Stage stage = new Stage();

DialogPane dialogPane = new DialogPane();
dialogPane.setHeaderText("HeaderText");
dialogPane.setContentText("ContentText");

ImageView imageView = new ImageView("image\\portrait.jpg");
imageView.setFitWidth(50);
imageView.setPreserveRatio(true);
dialogPane.setGraphic(imageView);

Text text1 = new Text("ExpandableContentExpandableContent");
Text text2 = new Text("ExpandableContentExpandableContent");
text1.setFill(Paint.valueOf("#ccc"));
text1.setFont(Font.font(20));
VBox vBox = new VBox(text1, text2);
dialogPane.setExpandableContent(vBox);
dialogPane.setExpanded(true);

dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.APPLY, ButtonType.CANCEL);
Button btnOk = (Button) dialogPane.lookupButton(ButtonType.OK);
Button btnApply = (Button) dialogPane.lookupButton(ButtonType.APPLY);
Button btnCancel = (Button) dialogPane.lookupButton(ButtonType.CANCEL);
btnOk.setOnAction(new EventHandler<ActionEvent>() {
    @Override
    public void handle(ActionEvent event) {
        System.out.println("OK");
        stage.close();
    }
});

stage.initOwner(primaryStage);
stage.initModality(Modality.WINDOW_MODAL);
stage.setResizable(false);
stage.setScene(new Scene(dialogPane));
stage.show();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章