The following code should work:
iconid.setOnMouseClicked( event -> {
Stage obj = (Stage) iconid.getScene().getWindow();
obj.setIconified(true);
});
Edit: I'm new here so I didn't know to present my code better. So I'll try my best.
Here's the expln:-
Variable meanings-
iconid
: The fxid of your ImageView element.
obj
: random stage object that you can declare.
The event ->{}
is a lambda function and it reduces my work so I use it often.
What the second line does is it creates a new stage object and equates it to the current stage being shown, which is retrieved using .getScene().getWindow()
property. I used the same ImageView element for consistency but you can use any element belonging to the same stage.(e.g. a button from the same window)
Third line is where you call the method setIconified(boolean)
[Not the best naming ik, but I think it has to do with 'iconifying' it to the taskbar-turning it into an icon from a window] Setting it to 'true' minimizes your specified window.
That's about it.