4
左側設定圖像I創建爲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;
}
}
我很感興趣,我可以如何設置對話框左側的圖像。
有人設法改變圖像的一面嗎?
截圖?哪個圖像? – JonasCz 2015-04-01 14:29:28
請發佈其他人可以運行的代碼。沒有人可以訪問您的圖像文件。 – 2015-04-01 14:43:31
@James_D發佈更新 – 2015-04-01 14:58:12