9

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.

gal kogeman
  • 89
  • 1
  • 1
  • 9

2 Answers2

15

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);
jewelsea
  • 150,031
  • 14
  • 366
  • 406
ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
0

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.

sazzy4o
  • 3,073
  • 6
  • 34
  • 62