I have a JavaFX WebView which I want to have as big as the scene on start. If I could make it resize with the scene, this would be perfect.
But right now I focus just on the initial size.
@Override
public void start(Stage stage) {
try {
Scene scene = new Scene(createWebViewPane(), 1920, 1080);
scene.getStylesheets().add(getClass().getResource("Styles/application.css").toExternalForm());
stage.setScene(scene);
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
The above code creates a scene with width: 1920px, height: 1080px. createWebViewPane()
creates a WebView on a pane.
private Pane createWebViewPane() {
final Pane pane = new Pane();
pane.minWidth(1920);
pane.minHeight(1080);
WebView browser = new WebView();
browser.minWidth(1920);
browser.prefWidth(1920);
browser.minHeight(1080);
browser.prefHeight(1080);
WebEngine webEngine = browser.getEngine();
webEngine.load(getClass().getResource("index.html").toExternalForm());
pane.getChildren().add(browser);
return pane;
}
There I try to set the width / height. I also set it in the stylesheet.
web-view{
-fx-font-scale: 1;
-fx-min-width: 1920px;
-fx-min-height: 1080px;
-fx-pref-width: 100%;
-fx-pref-height: 100%;
}
But none of these properties seem to affect the WebView. It still has it's default size. 800px in width and 600px in height.
StackPane
, as shown here. – Arak