2 Replies Latest reply: Dec 26, 2012 9:37 AM by Kishori Sharan RSS

    Inheriting -fx-text-alignment CSS Property

    Kishori Sharan
      Hello,

      I am referring to the Inheritance section in the following document:
      http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#typefont

      The document states that the three CSS properties are inherited by a node from its parent, by default:
      -fx-cursor
      -fx-text-alignment
      -fx-font

      The following program is to demonstrate the above CSS rule.
      package test;
      
      import javafx.application.Application;
      
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.VBox;
      import javafx.scene.text.Text;
      
      import javafx.stage.Stage;
      
      
      public class Test extends Application {
           public static void main(String[] args) {
                Application.launch(args);
           }
      
           public void start(Stage stage) {
                VBox root = new VBox();
                root.setStyle("-fx-cursor: hand;" + 
                              "-fx-text-alignment: right;" + 
                              "-fx-font: normal bold 20px \"serif\"");
      
                Label lb2 = new Label("Just adding a long text to test the text alignment:");
                lb2.setWrapText(true);
                //lb2.setStyle("-fx-text-alignment: inherit");
      
                Text t2 = new Text("This is a big text for the Text node");
                lb2.setPrefWidth(100);
                t2.setWrappingWidth(50);
               //t2.setStyle("-fx-text-alignment: inherit");
                
                root.getChildren().addAll(lb2, t2);
      
                Scene scene = new Scene(root);
                scene.getStylesheets().add("resources/css/hjfx.css");
      
                stage.setScene(scene);
                stage.setTitle("Test");
                stage.show();
           }
      }
      I have the following questions:
      1. The -fx-text-alignment property is not inherited by default by the Label and Text nodes. If I specify the value as inherit, it works as expected.
      2. The textAlignment property is not just defined in the Text class. It is also defined in the Labeled class. The font property is not defined in the Font class either. Why does this document refer to these classes in the table in the Inheritance section?
      3. Can someone give me an example of what does this document mean by stating that -fx-text-alignment property is inherited by nodes from their parents, by default.

      Thanks
      Kishori