Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Css for javafx.scene.text.Text

Tags:

css

javafx

I want to change color and font size of content of javafx.scene.text.Text but couldn't seem to find the correct css. I used the following but there were no visible changes.

.text { 
 -fx-font-smoothing-type: lcd;
 -fx-fill: white;
 -fx-font-size: 11pt;
}

Can anyone please tell me how can I change the color and size of javafx.scene.text.Text using css?

like image 862
Harshita Sethi Avatar asked Feb 09 '16 05:02

Harshita Sethi


People also ask

How to set string as text in JavaFX scene text object?

It is a double type property. The class javafx.scene.text.Text needs to be instantiated in order to create the text node. Use the setter method setText (string) to set the string as a text for the text class object. Follow the syntax given below to instantiate the Text class.

What is JavaFX CSS?

CSS in JavaFX. JavaFX provides you the facility of using CSS to enhance the look and feel of the application. The package javafx.css contains the classes that are used to apply CSS for JavaFX applications. A CSS comprises of style rules that are interpreted by the browser and then applied to the corresponding elements in your document.

How to underline the text in a scene in JavaFX?

It defines the text string which is to be displayed. It is a boolean type property. We can underline the text by setting this property to true. Width limit for the text from where the text is to be wrapped. It is a double type property. The class javafx.scene.text.Text needs to be instantiated in order to create the text node.

How to apply different fonts in JavaFX text nodes?

Font and position of the Text. JavaFX enables us to apply various fonts to the text nodes. We just need to set the property font of the Text class by using the setter method setFont(). This method accepts the object of Font class. The class Font belongs the package javafx.scene.text. It contains a static method named font().


1 Answers

The content CSS is not available for Text node in javafx. If you apply .text{} it will apply to all button text and others but not to the Text node which you required.
But, you can use style class in css and use the same in fxml as given below.

.text-id { 
 -fx-font-smoothing-type: lcd;
 -fx-fill: white;
 -fx-font-size: 11pt;
}

Then in FXML,

<Text layoutX="238.0" layoutY="141.0" strokeType="OUTSIDE" strokeWidth="0.0" styleClass="text-id" text="NEW TEXT" />

I hope it will help you.

like image 156
Venkat Prasanna Avatar answered Sep 29 '22 07:09

Venkat Prasanna