How to set style color for string in javafx?

How to set style color for string 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 so that the lines are not painted.

I would be glad if you could help me.

+4
source share
2 answers

Use -fx-strokefor coloring lines (using CSS)

line.setStyle("-fx-stroke: red;");

Or call setStroke () for coloring lines (using the Java API):

line.setStroke(Color.RED);
+4
source

I suggest using a for loop to get the children of the "lines" array, and then using "-fx-stroke:", as ItachiUchiha suggested, but adding color to the line.

Here is the code:

public void setColor(String color) {
  for (Line line:lines){ 
      line.setStyle("-fx-stroke:"+ color);
  }
}

Hope this helps. If you have a question, just ask.

-1
source

All Articles