2

I am working on a project and have embedded a JavaFx Browser in a java application. Now, I would like to display some contents in the Browser.

I wanted to know that is there a way to display the contents through a string that contains HTML tags. I do not want to create a HTML file and the display the contents.

I was looking for something like JTextPane.

1
  • not sure i understand your question, if you already have an embedded browser setup, why use JTextPane? well, anyways, if you simply need a small thing that displays html you can use JLabel. does do myLabel.setText( "<html><b>this is bold text</b>" ); Commented Jun 28, 2012 at 13:43

3 Answers 3

6

I could not investigate that JavaFX Browser Netbeans Module in depth. But if it is using a JavaFX WebView control internally then you can load String value containing HTML page (or tag) via WebView's WebEngine. See the WebEngine API for different content loadings. That Netbeans Module should have some interface API allowing this.

The method you want is webView.getEngine().loadContent(htmlString)

Sign up to request clarification or add additional context in comments.

Comments

1

You have to change the < to &lt, followed by a semicolon, and change the > to &gt, followed by a semicolon.

Just like I did to type this answer.

Comments

0

When creating the "Scene" and adding it to the JFXPanel you want to put it in the JavaFX thread by using Platform.runLater :

 import javafx.application.Platform;
 import javafx.embed.swing.JFXPanel;

    String HTML_TO_SEND = GetHTML();

    Platform.runLater(new Runnable() {
        @Override
        public void run() {
  browser = new WebView();
  webEngine = browser.getEngine();
  webEngine.loadContent(HTML_TO_SEND);

  browser.setVisible(true);
  Scene scene = new Scene(browser);
    jfxPanel.setScene(scene);


        }
  });   

You can then add the jfxPanel to your Swing stuff as usual.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.