从最小化 WebView 恢复后在 javafx 中被禁用

after restore from minimize WebView become disabled in javafx

我的问题是当我从 windows 任务栏 WebView 恢复最小化的 javafx 应用程序时被禁用。

调整大小阶段后,它会启用。

Main java Code:

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            AnchorPane root = new AnchorPane();
            FXMLLoader loader = new FXMLLoader(getClass().getResource("Browser.fxml"));
            root = loader.load();
            Scene scene = new Scene(root);
            primaryStage.setScene(scene);
            primaryStage.setTitle("Shivam Jewels ERP");
            primaryStage.setMaximized(true);
            primaryStage.show();
            primaryStage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {

                @Override
                public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                    if (t1) {
                        System.out.println("minimized:");
                    }
                }
            });
            primaryStage.maximizedProperty().addListener(new ChangeListener<Boolean>() {

                @Override
                public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                    if (newValue) {
                        System.out.println("maximized:");
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

My JavaFX Code Is:

public class BrowserController implements Initializable {
    @FXML
    private WebView browser;
    @FXML
    private GridPane grdPn;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        final WebEngine webEngine = browser.getEngine();
        browser.getEngine().setUserStyleSheetLocation(getClass().getResource("application.css").toExternalForm());
        browser.setContextMenuEnabled(false);
        System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
        webEngine.load("http://192.168.2.6:4200");
    }

}

This is my CSS Code:

 ::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    -webkit-border-radius: 10px;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    -webkit-border-radius: 10px;
    border-radius: 10px;
    background: rgba(0,0,0,0.5); 
}
 ::-webkit-scrollbar-thumb:window-inactive {
    background: rgba(0,0,0,0.1);
}

This is my FXML Code:

 <?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.web.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="382.0" prefWidth="353.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.BrowserController">
   <children>
      <GridPane fx:id="grdPn" layoutX="57.0" layoutY="135.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <columnConstraints>
          <ColumnConstraints hgrow="SOMETIMES" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints fillHeight="false" valignment="CENTER" vgrow="SOMETIMES" />
          <RowConstraints vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <WebView fx:id="browser" minHeight="-1.0" minWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS" />
         </children>
      </GridPane>
   </children>`enter code here`
</AnchorPane>

这实际上是一个 JDK 多次报告的错误 here, here and here。您描述的行为发生在 satge 最大化时。

此错误原计划在 JDK9 中修复,但根据 this 也将在 JDK8u122 中修复:

Approved to backport to 8u-dev for 8u122.

JDK8u122is planned to be released in January 2017 so it won't be long before we can use it but for now you can download and use early access release from JDK 8u122 early access page.

我自己下载并测试了代码,幸运的是问题已经不存在了。