1

I have an app that I want to have an ImageView element in the FXML file display either an image, or a blank section dependant on user input. I was thinking either to somehow surround the FXML imageview element in an if/else block, or to pass either the image filepath, but both of these feel "off" (the former adding back end loging to front end code, the latter having no image path if set to not display and having to handle that somehow).

Would anyone know of a better way to perform an operation like what I'm describing above?

canadiancreed
  • 1,966
  • 6
  • 41
  • 58

1 Answers1

1

control are initialized in fxml are static, so it not possible to be created imageview directly...

you can use another way i think its work...

1.take a anchor pane,vbox,hbox etc any container.

2.and set image on runtime in this container.

3.like example below.

AnchorPane pne = new AnchorPane();
if(flag==1)
pne.getChildren.add(new ImageView(new Image(getClass().getResourceAsStream("image.png"))));
Anshul Parashar
  • 3,096
  • 4
  • 30
  • 56