1
votes

I am trying to open a html file using webview in JavaFX. When I'm resizing the window there is no word wrap. Here is my code:

 WebEngine xwebEngin=null;
 Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
 Group gp=new Group();
 Scene scn=new Scene(gp);
 fm1.setScene(scn);    
 WebView wb=new WebView();
 gp.getChildren().add(wb);

 wb.setMaxSize(screenSize.width-20,screenSize.height-70);
 wb.setMinSize(screenSize.width-20,screenSize.height-70);

 xwebEngin=wb.getEngine();
 File htmlFile = new File("d:/new folder/abc.htm)";

 try {
     xwebEngin.load(htmlFile.toURI().toURL().toString());
 }
 catch(Exception ex) {}
1

1 Answers

0
votes

WebView supports word wrap by default.

But you assigned fixed minimal size to WebView by

wb.setMinSize(screenSize.width-20, screenSize.height-70);

Thus Group can't shrink your WebView, and then WebView is bigger then window it looks like words are being cut.

Use setPrefSize() instead of min/max or try next code:

    WebView wb = new WebView();
    Scene scn = new Scene(wb);
    fm1.setFullScreen(true);
    WebEngine xwebEngin  = wb.getEngine();
    xwebEngin.load("d:/new folder/abc.htm");
    fm1.setScene(scn);