How to minimize, maximize and restore down through buttons in java?

久未见 提交于 2019-12-05 12:04:42

To minimize the stage into task bar set an action for your minimize button similar to this:

    btnMinimize.setOnAction(new EventHandler<ActionEvent>() {

        public void handle(ActionEvent event) {
            Stage stage = (Stage)((Button)event.getSource()).getScene().getWindow();
            // is stage minimizable into task bar. (true | false)
            stage.setIconified(true);
        }
    });

I use JavaFX 8 therefore I don't know if it will work with JavaFX 2.2

You have to call your stage object in your main class. This only could be the stage object which could manipulate the Window.

See : http://docs.oracle.com/javafx/2/api/javafx/stage/Stage.html

code for minimize

  @FXML private void minimizeBut()
{
    Stage stage=(Stage) minimize.getScene().getWindow();
    stage.setIconified(true);
}

In JavaFX8

@Override
public void start(Stage stage) {
    //Maximized
    stage.setMaximized(true);

    //Restore down
    stage.setMaximized(false);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!