【发布时间】:2015-04-01 14:27:35
【问题描述】:
我为 JavaFX8u40 的 JavaFX 警报对话框创建了这个非常简单的示例。
public class MainApp extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
private Stage stage;
@Override
public void start(Stage primaryStage) throws Exception
{
Button create = new Button("Create Alert");
create.setTooltip(new Tooltip("Create an Alert Dialog"));
create.setOnAction(e ->
{
createAlert();
});
primaryStage.setScene(new Scene(create));
primaryStage.show();
stage = primaryStage;
}
protected Alert createAlert()
{
Alert alert = new Alert(AlertType.WARNING);
Image image1 = new Image("http://www.mcaprojecttraining.com/images/java-big-icon.png");
ImageView imageView = new ImageView(image1);
alert.setGraphic(imageView);
alert.initModality(Modality.APPLICATION_MODAL);
alert.initOwner(stage);
alert.getDialogPane().setContentText("Some text");
alert.showAndWait()
.filter(response -> response == ButtonType.OK)
.ifPresent(response -> System.out.println("The alert was approved"));
return alert;
}
}
我对如何在对话框左侧设置图像感兴趣。
有人设法改变图像的侧面吗?
【问题讨论】:
-
截图?哪张图?
-
请发布其他人可以运行的代码。没有人可以访问您的图像文件。
-
@James_D 帖子已更新
-
为什么是 javafx-2 标签?它是 8u40 中的新 api,不是吗?