aspose file tools*
The moose likes JavaFX and the fly likes Creating an FX label with HTML formating Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Creating an FX label with HTML formating" Watch "Creating an FX label with HTML formating" New topic
Author

Creating an FX label with HTML formating

Robert Haynes
Greenhorn

Joined: Mar 09, 2012
Posts: 12
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

Joined: May 03, 2008
Posts: 4642
    
    5

You could use a WebView.


luck, db
There are no new questions, but there may be new answers.
Robert Haynes
Greenhorn

Joined: Mar 09, 2012
Posts: 12
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

Joined: May 03, 2008
Posts: 4642
    
    5

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

Joined: Mar 09, 2012
Posts: 12
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

Joined: May 03, 2008
Posts: 4642
    
    5

You are asking about JavaFX 2, aren't you? I quoted that directly from the API.
John Damien Smith
Ranch Hand

Joined: Jan 26, 2012
Posts: 147
    
    9
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.
 
Consider Paul's rocket mass heater.
 
subject: Creating an FX label with HTML formating