Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:03:54+00:00 2026-06-15T13:03:54+00:00

How can I append text to webengine? I tried this: public TabMessage(String title) {

  • 0

How can I append text to webengine? I tried this:

public TabMessage(String title) {
    super(title);
    view = new WebView();
    engine = view.getEngine();
    engine.loadContent("<body></body>");
    view.setPrefHeight(240);
}

private void append(String msg){
    Document doc = engine.getDocument();
    Element el = doc.getElementById("body");
    String s = el.getTextContent();
    el.setTextContent(s+msg);
}

But document is null

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:03:56+00:00Added an answer on June 15, 2026 at 1:03 pm

    You can also use JavaScript to do the append.

    final WebEngine appendEngine = view.getEngine();
    btn.setOnAction(new EventHandler<ActionEvent>() {
     @Override public void handle(ActionEvent event) {
       appendEngine.executeScript(
         "document.getElementById('content').appendChild(document.createTextNode('World!'));"
       );
     }
    });
    

    I sometimes find it simpler to use jQuery to manipulate the DOM rather than the Java Document or native JavaScript DOM interfaces.

    final WebEngine appendEngine = view.getEngine();
    btn.setOnAction(new EventHandler<ActionEvent>() {
     @Override public void handle(ActionEvent event) {
       executejQuery(appendEngine, "$('#content').append('World!');");
     }
    });
    
    ...
    
    private static Object executejQuery(final WebEngine engine, String script) {
      return engine.executeScript(
        "(function(window, document, version, callback) { "
        + "var j, d;"
        + "var loaded = false;"
        + "if (!(j = window.jQuery) || version > j.fn.jquery || callback(j, loaded)) {"
        + " var script = document.createElement(\"script\");"
        + " script.type = \"text/javascript\";"
        + " script.src = \"http://code.jquery.com/jquery-1.7.2.min.js\";"
        + " script.onload = script.onreadystatechange = function() {"
        + " if (!loaded && (!(d = this.readyState) || d == \"loaded\" || d == \"complete\")) {"
        + " callback((j = window.jQuery).noConflict(1), loaded = true);"
        + " j(script).remove();"
        + " }"
        + " };"
        + " document.documentElement.childNodes[0].appendChild(script) "
        + "} "
        + "})(window, document, \"1.7.2\", function($, jquery_loaded) {" + script + "});"
      );
    }
    

    Whether you use the Java Document API, as Uluk has, or JavaScript or JQuery APIs, all of the other points in Uluk’s excellent answer still apply.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HTML is <a>ref</a> I need to get <a>ref</a>text How can i do this? $('a').append('text')
Is there a way that I can always append new text into the beginning
How can I append this <% =i %> variable onto this. <asp:DropDownList ID=AdTitle runat=server>
How can I append text to every cell in a column in Excel? I
Can I alter the text of a JTextArea to bold (append text) and then
I have a string in the format: t='@abc @def Hello this part is text'
How can we append text in a file via a one-line command without using
How can I append a blurb of text into my first LI s' <ul
How can I append variable/text to the attribute href in jquery ?
Is there a command that can append one array of char onto another? Something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.