• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating an FX label with HTML formating

 
Robert Haynes
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the process of messing around with FX, I am attempting to replicate a seemingly simple task of creating a label.

Previously, JLabel was being used and some HTML formatting was done and the text displayed in formatted HTML.


Is there a way to do so in FX? What I have so far is not working right and merely displays the text verbatim with no formatting.



Thanks
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a WebView.
 
Robert Haynes
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The webview appears to be for embedding a browser in the application rather then a single line of text that contains some HTML formatting. I have searched a bit and can not locate much beyond the browser usage. Do you have an example of what you're suggesting?

An example of what I have found:
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you gone through the API for the two classes mentioned in your code? Do you see a method that is documented to do this?
Loads the given HTML content directly. This method is useful when you have an HTML String composed in memory ...
 
Robert Haynes
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To the best of my understanding, I have reviewed the API's and nothing seems to jump out which is was led me to post on the forums.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are asking about JavaFX 2, aren't you? I quoted that directly from the API.
 
John Damien Smith
Ranch Hand
Posts: 271
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Darryl is right, use a WebView with the loadContent api.

Call label.setGraphic and label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY) to make the Label display only the WebView.

Size the webView to the correct size using the technique in this Oracle JavaFX forum thread on sizing WebViews based on rendered content.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic