Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimize window in javafx2

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?

like image 220
velsachin Avatar asked Dec 13 '12 06:12

velsachin


2 Answers

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..

like image 109
velsachin Avatar answered Oct 28 '22 19:10

velsachin


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.

like image 29
Rakshit Shetty Avatar answered Oct 28 '22 20:10

Rakshit Shetty