Dgo*_*got 2 java javafx intellij-idea
我很新JavaFx,我正在尝试做的是创建一个带有自定义图片的警报对话框。
首先,我正在使用IntelliJ idea,但我不明白在.jpg项目中的位置(见附图)。
Alert alert = new Alert(Alert.AlertType.ERROR, "Error", ButtonType.OK);
alert.showAndWait();
Run Code Online (Sandbox Code Playgroud)
谢谢
在 IntelIJ 中包含一个资源已经是多个问题的主题,我不会在这里再次回答。请阅读有关此主题的其他问题的答案之一,例如maba 对在 intellij 中为 java 项目添加资源的回答。
自定义图像可以用于通过设定ImageView为graphic用于Dialog:
Image image = new Image("https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/Emojione_1F62D.svg/64px-Emojione_1F62D.svg.png");
ImageView imageView = new ImageView(image);
alert.setGraphic(imageView);
alert.showAndWait();
Run Code Online (Sandbox Code Playgroud)
请注意,此示例使用来自网络的图像。对于作为资源添加的图像,您可以使用类似
Image image = new Image(getClass().getResource("/path/to/resource/image.jpg").toExternalForm());
Run Code Online (Sandbox Code Playgroud)
反而。
| 归档时间: |
|
| 查看次数: |
6761 次 |
| 最近记录: |