本文介绍了JavaFX Stage.setMaximized仅在Mac OSX上运行一次(10.9.5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行最新的JDK:1.8.0_102,但它在1.8.0_45上也失败了。
这是我复制问题的简单程序。重现的步骤:

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. 运行程序

  2. 点击最大化(它将正确最大化)

  3. 点击恢复(它将正确地取消最大化)

  4. 再次点击最大化(它不会做任何事情)。

  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);
}
}



推荐答案

最大化必须设置为false才能再次运行!一旦您对舞台进行图标化,请尝试将maxim设置为false。如果maxim已经设置为true,则不会发生任何事情。希望这可以帮助!

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);
    }

这篇关于JavaFX Stage.setMaximized仅在Mac OSX上运行一次(10.9.5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 16:25