如何在javafx中为一行设置样式颜色?

时间:2022-12-26 23:42:49

How to set style color for a line in javafx?

如何在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.

所有的4个注释都没有改变线条的颜色。

I would be happy if you could help me.

如果你能帮助我,我会很高兴的。

2 个解决方案

#1


4  

Use -fx-stroke for coloring lines (using CSS)

使用-fx-stroke绘制线条(使用CSS)

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

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

或调用setStroke()对着色线(使用Java API):

line.setStroke(Color.RED);

#2


-1  

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.

我建议使用for循环来获取“lines”数组的子元素,然后使用“-fx-stroke:”,就像ItachiUchiha建议的那样,但将颜色添加到字符串中。

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.

我希望这可以帮助。有问题尽管问。

#1


4  

Use -fx-stroke for coloring lines (using CSS)

使用-fx-stroke绘制线条(使用CSS)

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

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

或调用setStroke()对着色线(使用Java API):

line.setStroke(Color.RED);

#2


-1  

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.

我建议使用for循环来获取“lines”数组的子元素,然后使用“-fx-stroke:”,就像ItachiUchiha建议的那样,但将颜色添加到字符串中。

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.

我希望这可以帮助。有问题尽管问。