JavaFX style by classname

后端 未结 2 717
[愿得一人]
[愿得一人] 2021-01-24 04:52

Perhaps a little basic question, but is it possible to style elements of a table by classname in JavaFX. So for example like this:

MyClassname .table-view .colum         


        
相关标签:
2条回答
  • 2021-01-24 04:54

    Yes, styling based upon class name selectors is supported - it's based on Node.getTypeSelector(), which comes from the Styleable interface.

    The type of this Styleable that is to be used in selector matching. This is analogous to an "element" in HTML. (CSS Type Selector).

    Returns: getClass().getName() without the package name

    So you could style all Labels to have a green text fill using the CSS rule:

    Label { -fx-text-fill: forestgreen; }
    

    Most nodes also have style classes which are set on them by the application or, if it is a standard control, by the JavaFX framework. The standard way most people code is not to use the type selectors but to use style class selectors instead:

    .label { -fx-text-fill: forestgreen; }
    

    The type selector information is documented in the JavaFX CSS reference guide:

    Node's getTypeSelector method returns a String which is analogous to a CSS Type Selector. By default, this method returns the simple name of the class. Note that the simple name of an inner class or of an anonymous class may not be usable as a type selector. In such a case, this method should be overridden to return a meaningful value.

    0 讨论(0)
  • 2021-01-24 05:21

    Specify the full path to your class from root.

    .root MyClassname .table-view .column-header .label {
        -fx-text-fill:#F00;
    }
    
    0 讨论(0)
提交回复
热议问题