after restore from minimize WebView become disabled in javafx
Asked Answered
M

1

6

My problem is when I am restoring minimized javafx application from windows taskbar WebView become disabled.

After resize stage it becomes enabled.

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>
Makowski answered 27/12, 2016 at 5:16 Comment(2)
This code works fine for me. Can you provide fxml and css files?Rhetoric
Thanks for your response see my last update for further details.Makowski
R
3

This is actually a JDK bug reported multiple times here, here and here. The behavior you described happens when satge is maximized.

This bug was scheduled to be fixed in JDK9 but according to this is also going to be fixed in JDK8u122:

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

JDK 8u122 is 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.

I myself downloaded it and tested the code and fortunately problem no longer exists.

Rhetoric answered 30/12, 2016 at 9:22 Comment(2)
After changing version of java it's working for me. ThanksMakowski
This appears to be happening again on windows 10 only.Interweave

© 2022 - 2024 — McMap. All rights reserved.