I am working on a JavaFX project in which I have a bunch of static HTML&JS pages and I am loading the index.html
which the users can check out and click on links, etc.
Now, generally when we are using a browser like Firefox
or Chromium
, then calling the print command does the printing task.
BUt that is not the same thing happening in the webview
. How do I enable printing in JavaFX's webpage rendering mechanism.
What is also okay is some way to call a print function and pass it the webpage or webview from JavaScript.
Here is my code so far :
public class Main extends Application {
private Scene scene;
MyBrowser myBrowser;
@Override
public void start(Stage primaryStage) throws Exception{
primaryStage.setTitle("Test web");
Screen screen = Screen.getPrimary();
myBrowser = new MyBrowser();
scene = new Scene(myBrowser, 1080, 1920);
myBrowser.setPrefSize(1080, 1920);
Rectangle2D bounds = screen.getVisualBounds();
primaryStage.setX(bounds.getMinX());
primaryStage.setY(bounds.getMinY());
scene.setRoot(myBrowser);
primaryStage.setScene(scene);
primaryStage.setMaximized(false);
primaryStage.setFullScreen(true);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
class MyBrowser extends Region {
final String hellohtml = "hello.html";
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
public MyBrowser(){
URL urlHello = getClass().getResource("hello.html");
webEngine.load(urlHello.toExternalForm());
webView.setPrefSize(1080, 1920);
webView.getChildrenUnmodifiable().addListener(new ListChangeListener<Node>() {
@Override public void onChanged(Change<? extends Node> change) {
Set<Node> deadSeaScrolls = webView.lookupAll(".scroll-bar");
for (Node scroll : deadSeaScrolls) {
scroll.setVisible(true);
}
}
});
getChildren().add(webView);
}
}
Any suggestions or pointers would be nice. Thank you.. :-)