Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style a SVG using CSS in javaFX FXML

I'm using SVG for an image in a button. But I'm not able to fill in color for it through CSS. Below is the code to render a button.

<Button  onAction="#closeApplication" >
<graphic>
 <SVGPath content="M10,16 10,0 0,8z" styleClass="button‐icon‐shape" />
</graphic>
</Button>

here is the css

.button-icon-shape SVGPath{
   -fx-fill:  red;
}
like image 296
user68883 Avatar asked Feb 24 '16 14:02

user68883


People also ask

How do I add CSS to FXML?

Adding stylesheet through FXMLThe @ symbol before the name of the css file in the URL indicates that the style sheet is in the same directory as the FXML file. That's it! You can now run the application, it'll pick the styles from the css file and style the ui elements.

Can you use CSS in JavaFX?

This topic describes how to use cascading style sheets (CSS) with JavaFX applications. Use CSS to create a custom look for your application. Style sheets contain style definitions that control the look of user interface elements. Using CSS in JavaFX applications is similar to using CSS in HTML.

What is CSS JavaFX?

CSS styles are applied to nodes in the JavaFX scene graph in a way similar to the way CSS styles are applied to elements in the HTML DOM. Styles are first applied to the parent, then to its children. The code is written such that only those branches of the scene graph that might need CSS reapplied are visited.


1 Answers

here is how it worked. I had to style the button and use the class to style the svg in the button.

<Button  onAction="#closeApplication" styleClass="closeButton">
        <graphic>
            <SVGPath content="M10,16 10,0 0,8z"  />
        </graphic>
</Button>

here is the css

.closeButton{

}
.closeButton SVGPath{
   -fx-fill:  red;
}
like image 200
user68883 Avatar answered Oct 01 '22 05:10

user68883