简体   繁体   中英

JavaFX Stage.setMaximized only works once on Mac OSX (10.9.5)

I am running with latest JDK: 1.8.0_102, but it also failed on 1.8.0_45. Here is my simple program to replicate the issue. Steps to reproduce:

  1. Run program
  2. Click Maximize (it will maximize correctly)
  3. Click Restore (it will "unmaximize" correctly)
  4. Click Maximize again (it will not do anything).

     import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class TestApplication extends Application { @Override public void start(Stage primaryStage) throws Exception { VBox pane = new VBox(); Button maximizeButton = new Button("Maximize"); pane.getChildren().add(maximizeButton); Button restoreButton = new Button("Restore"); pane.getChildren().add(restoreButton); maximizeButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { primaryStage.setMaximized(true); } }); restoreButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { primaryStage.setMaximized(false); } }); primaryStage.setScene(new Scene(pane)); primaryStage.show(); } public static void main(String[] args) { launch(args); } } 

Maximize must be set to false before it can work again! Try setting maximize to false once you iconize the stage. If maximize is already set to true nothing will happen. Hope this helps!

example!!


public static void maximize() {
        if (!stage.isMaximized()) {
            stage.setWidth(Utils.WIDTH);
            stage.setHeight(Utils.HEIGHT);
            stage.setX(0);
            stage.setY(0);
            stage.setMaximized(true);
        } 
        else {
            if (stage.getX() != 0 && stage.getY() != 0) {
                stage.setWidth(Utils.WIDTH);
                stage.setHeight(Utils.HEIGHT);
                stage.setX(0);
                stage.setY(0);
            } 
            else if (stage.getX() == 0 && stage.getY() == 0) {
                stage.setMaximized(false);
                stage.setWidth(Utils.WIDTH * .8);
                stage.setHeight(Utils.HEIGHT * .8);
                stage.setX(200);
                stage.setY(85);
            }
        }
    }

    public static void minimize() {
        stage.setIconified(true);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM