Skip to content
Advertisement

How show or hide images in condition with javafx

I need help to program a windows based application with JavaFX. I simply want to show or hide some images with if/else condition. what I exactly want is something like this: if x=1 then show image1 if x=2 them show image2

I tried setvisible() and setDisable() methodes to do this, but it doesn’t work.

JavaScript

and my .fxml file codes are:

JavaScript

Advertisement

Answer

In the if statement you used the assignment operator (=) instead of comparison operator == .

JavaScript

Example of working code:

JavaScript

Anyway, is better use the setImage() method to set/change pictures in a ImageView.

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/image/ImageView.html

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement