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?
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.
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.
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.
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().
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With