I'm using a listener for the state of the web engine and it's working fine. Also the document is filled at this time, because the State SUCCEEDED is reached.
The State Listener:
public class WebViewListener implements ChangeListener<Worker.State> {
public void changed(ObservableValue observable, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
String style = "";
try {
style = cssModel.getRuntimeCSSFileAsString();
htmlModel.setDocument(view.getWebEngine().getDocument());
htmlModel.setStyleAttribute(style);
} catch (IOException e) {
e.printStackTrace();
} catch (HTMLDocumentNullException e) {
e.printStackTrace();
}
}
}
}
My problem is, that I use another listener on a toggle button, which I manually fire by the method selectToggle() at an earlier time (in the constructor of another view), where the document model of the web engine is not yet set by the state listener, because the State SUCCEED is not reached before the JavaFX stage pops up.
So now I need a solution, how I can listen on the JavaFX Stage, when the UI is rendered. Because at this time, the State listener reacts and after that I could call the setInitialState() Method and work with the document model of the web engine.
The code of selecting the ToggleButton:
public void setInitialState() {
screenGroup.selectToggle(rbMasterScreen);
elementGroup.selectToggle(btnButton);
}