Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styled text in JavaFX?

I'm switching my chat client over from Swing to JavaFX, and I have run into a graphical problem. Previously, I was using a JTextPane to insert styled text, but upon switching to FX, I could not find a single component capable of doing what the JTextPane did, and from this answer, I know that FX's TextPane will not do the job either. Sorry if this is obvious to you JavaFX veterans, but I can't quite seem to find anything.

Please, if you could recommend a component like this, it would be much appreciated. Thank you in advance.

like image 289
mattbdean Avatar asked Nov 10 '12 02:11

mattbdean


People also ask

How do you write text in javafx?

Adding Text. To add a text object to your application, use any of the constructors shown in Example 1 through Example 3. Text t = new Text (10, 20, "This is a text sample"); You can also create text objects by using the javafx.

How do you change the color of text in javafx?

If you are designing your Javafx application using SceneBuilder then use -fx-text-fill (if not available as option then write it in style input box) as style and give the color you want,it will change the text color of your Textfield .

How do I bold text in FXML?

Add this in your fxml style="-fx-font-weight: bold;" or this in your css stylesheet : . label { -fx-font-weight: bold;} .


1 Answers

Styled text will is available in JavaFX 8 (included in jdk8 and jre8) via the TextFlow component.

Here are the details and samples of the feature.

The feature was implemented by the following Multi-line, multi-style, rich text support issue and the related issues it references.

For older (now obsolete) JavaFX versions such as JavaFX 2.2, use a WebView to display styled text and an HTMLEditor to edit it. Or you can place multiple Text or Label nodes in a FlowPane.

like image 98
jewelsea Avatar answered Sep 21 '22 21:09

jewelsea