Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Would the CSS style set to a parent node be inherited to underlying nodes?

865876Jun 10 2011 — edited Jun 10 2011
Hi,

Would the CSS style set to a parent node be inherited to underlying nodes?

With below code, style setting to parent(VBox) is not getting inherited to children(Text).


Style.java
package style;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;


public class Style extends Application {

    public static void main(String[] args) {
        Application.launch(Style.class, args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World");
        Group root = new Group();
        Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN);
        scene.getStylesheets().add("/style/style1.css");
        
        // Create children
        Text text1 = new Text("Text1");
        Text text2 = new Text("Text2");
        
        // Create parent and set style
        VBox vBox = new VBox();
        vBox.getChildren().addAll(text1, text2);
        vBox.getStyleClass().add("font-normal");
        
        root.getChildren().add(vBox);        
        primaryStage.setScene(scene);
        primaryStage.setVisible(true);
    }
}
Style1.css
.font-normal {
    -fx-font-size: 9pt;
    -fx-font-family: "Arial";
    -fx-fill: #FF0000;
}
Edited by: Simosh on Jun 10, 2011 4:24 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 8 2011
Added on Jun 10 2011
2 comments
396 views