I have a Webview component inside a JavaFX Program (using FXML) and I want to open it to an external html which is supposed to be a loading screen. (it is necessary due to other background tasks getting perfomed like checking for the existence of a file every 5 seconds) Then after 5 seconds It is supposed to open the real html file (in this example : "google.com") and should open it.
The problem I've run into is that when i put a delay right after the first engine.load(""); and then after the delay another engine.load(""); with the proper website it will wait that time and then just open the second website without ever opening the first. So Using a delay without an additional Thread made the Program only open after that time has passed and only opened the second WebEngine.
Using a Thread worked when i put in Thread.sleep(5000); and after that only System.out.println("Hello World!"); but if I put anything related to JavaFX it gives the error that it cannot update the UI outside of Main Thread I haven't found an option to update the WebEngine Method to load a different website since i am unable to access it outside of my loading Method and Updating it from a different Thread is not allowed.
Using Platform.runLater() has given me nothing but errors because the WebEngine is either not recognized as the same Engine and gives the error that it cannot find the object or it gives the error that JavaFX cant update UI Elements outside of its own Thread.
@FXML
private void initialize() throws InterruptedException {
WebEngine engine = webView.getEngine();
String url = "";
try {
url = getClass().getResource("/index.html").toExternalForm();
} catch (Exception e) {
}
loadSub(url, engine);
}
boolean test = false;
private void loadSub(String website, WebEngine engine) {
engine.load(website); // load loading Screen
//wait 5 seconds
engine.load("Google.com"); //load appropiate website
}