I would like to display image(saved in project folder) in dialog window, but when I run my method showDialogWithImage I get FileNotFoundExcpetion: imgs\pic1.jpg (The system cannot find the file specified), although the image is located there.
I have tried load image on this way too:
Image image = new Image(getClass().getResourceAsStream(path));, but got the same problem.
Are there some others possibilities to load image to ImageView ?
Thank you for help!
My Java code is located in src\myProject\gui in project folder.
path="imgs\pic1.jpg" // imgs is located in project folder
public void showDialogWithImage(String path) {
final Stage dialogStage = new Stage();
logger.info(path);
InputStream is = null;
try {
is = new FileInputStream(path); // here I get FileNotFoundException
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Image image = new Image(is);
ImageView view = new ImageView();
view.setImage(image);
Button btnOK = new Button("OK");
btnOK.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
dialogStage.close();
}
});
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.setScene(new Scene(VBoxBuilder.create()
.children(view, btnOK).alignment(Pos.CENTER)
.padding(new Insets(35)).build()));
dialogStage.show();
}