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;
}
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.
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.
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With