I am trying to assign two different styles to the same type of node of a JavaFX application.
For example, suppose I have two Text nodes
<Text text="Welcome" GridPane.columnSpan="2" GridPane.halignment="CENTER"
GridPane.rowIndex="0" />
<Text text="Goodbye" GridPane.columnSpan="2" GridPane.halignment="CENTER"
GridPane.rowIndex="0" />
and an application.css
Text {
-fx-font-size: 15pt;
-fx-font-family: Tahoma;
-fx-font-weight: bold;
}
This way, I will style both texts with the same class. How can I create and assign two different styles to the two instances of Text?
You can use the id
attribute, to differentiate the two Text
nodes and apply different CSS on them
<Text text="Welcome" GridPane.columnSpan="2" GridPane.halignment="CENTER"
GridPane.rowIndex="0" id="text1"/>
<Text text="Goodbye" GridPane.columnSpan="2" GridPane.halignment="CENTER"
GridPane.rowIndex="0" id="text2"/>
and in the css file, you can have
#text1{
-fx-font-size: 10pt;
-fx-font-family: Tahoma;
-fx-font-weight: bold;
}
#text2{
-fx-font-size: 15pt;
-fx-font-family: Tahoma;
-fx-font-weight: regular;
}
P.S. You can also separate the same using different css class for the two texts. Please follow this link for more information
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments