2 Replies Latest reply: Mar 7, 2013 6:32 PM by jsmith RSS

    Text alignment on WebView

    966626
      I have the following code:
       String htmlTexto = "<HTML> <script> function miFuncion(){ alert('hola');}</script> <BODY>";
              htmlTexto += "<P style=\"text-align:justify;font-weight:bold;font-family:verdana;\">" 
                      + tesisActual.getRubro().replaceAll("\n", "<BR>\n") + "</P>";
      wbTexto.getEngine().loadContent(htmlTexto);
      wbTexto is a WebView and the text inside is ok, it puts Verdana as font, bold BUT left align on the text... I need to set it justify.
      Thanks in advance.

      Edited by: charlymoon on 25/02/2013 05:48 PM

      Edited by: charlymoon on 7/03/2013 11:15 AM
        • 1. Re: Text alignment on WebView
          966626
          The code with the style is with single quotes, the editor insist on change them to double quotes.
          • 2. Re: Text alignment on WebView
            jsmith
            I think text justification doesn't work in JavaFX 2.2.

            See:
            http://javafx-jira.kenai.com/browse/RT-17235 "HTMLEditor Justify button does nothing"

            The issue is marked as fixed in a later version of JavaFX.

            I tried a recent jdk8 snapshot release to see if it worked in the WebView and HTMLEditor and it didn't (jdk8b79, Win7):
            http://jdk8.java.net/download.html

            As the fix was pretty recent, it may just be that it will take a while for the fix to filter down to an early access binary build.

            Test for WebView:
            import static javafx.application.Application.launch;
            import javafx.application.*;
            import javafx.scene.Scene;
            import javafx.scene.web.WebView;
            import javafx.stage.Stage;
             
            public class JustifiedApp extends Application {
              private static final String loremIpsum = 
                "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
              private static final String htmlText = 
                "<p style='text-align:justify;font-weight:bold;font-family:verdana;'>" + loremIpsum + "</p>";
              
              @Override public void start(Stage stage) {
                WebView webview = new WebView();
                webview.getEngine().loadContent(htmlText);
            
                stage.setScene(new Scene(webview));
                stage.show();
              }
            
              public static void main(String[] args) { launch(args); }
            }
            Test for editor:
            import static javafx.application.Application.launch;
            import javafx.application.*;
            import javafx.scene.Scene;
            import javafx.scene.web.HTMLEditor;
            import javafx.stage.Stage;
             
            public class EditorApp extends Application {
              private static final String loremIpsum = 
                "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
              private static final String htmlText = 
                "<p style='text-align:justify;font-weight:bold;font-family:verdana;'>" + loremIpsum + "</p>";
              
              @Override public void start(Stage stage) {
                HTMLEditor editor = new HTMLEditor();
                editor.setHtmlText(htmlText);
            
                stage.setScene(new Scene(editor));
                stage.show();
              }
            
              public static void main(String[] args) { launch(args); }
            }
            Loading the exact same html into Firefox or IE will justify the text fine:
            <p style='text-align:justify;font-weight:bold;font-family:verdana;'>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
            You may want to file an additional bug for your specific case against the runtime project:
            http://javafx-jira.kenai.com
            The JavaFX developers could check if your issue is fixed against the latest development trunk and close your issue as duplicate if it is else otherwise fix it.