i have undecorate the window in javafx2. Now i want to minimize the window by means of the action. This is my code
minIcon.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
primaryStage.toBack();
}
});
The window is go back when another one is open. otherwise its not. pls let me know how how to do this?
After searching for some times i found answer myself.
minIcon.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
primaryStage.setIconified(true);
}
});
This works fine..
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With