Reputation: 93
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.
Upvotes: 9
Views: 21836
Reputation: 3343
I suggest using a for loop to get the children of the "lines"array and then using "-fx-stroke:" as ItachiUchiha suggested but adding the color to the string.
Here is the code:
public void setColor(String color) {
for (Line line:lines){
line.setStyle("-fx-stroke:"+ color);
}
}
I hope this helps. If you have any question just ask.
Upvotes: 0
Reputation: 36722
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);
Upvotes: 16