How to set style color for a line in javafx?
public void setColor(String color) {
for (int i = 0; i < 9; i++){
//lines[i].setFill(Color.BLUE);
//lines[i].setStyle("-fx-Background-color: yellow;");
//lines[i].setStyle("-fx-color:"+ color);
//setStyle("-fx-Foreground-color:"+ color);
}
}
All 4 comments do nothing the lines not colored.
I would be happy if you could help me.
You can apply colors to nodes in JavaFX using the setFill() and setStroke() methods. The setFill() method adds color to the surface area of the node whereas the setStroke() method applies color to the boundary of the node. Both methods accept an object of the javafx.
Applying Color to the NodessetFill(color); //Setting color to the stroke Color color = new Color. DARKSLATEBLUE circle. setStroke(color); In the above code block, we are using the static variables of the color class to create a color object.
The default css is always applied to every JavaFX application. However, you can create one or more custom stylesheets of your own and add them to your application to override the default styles defined by JavaFX.
Use -fx-stroke
for coloring lines (using CSS)
line.setStyle("-fx-stroke: red;");
Or call setStroke() for coloring lines (using Java API):
line.setStroke(Color.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