Java Fx用户选择颜色CSS

Java Fx用户选择颜色CSS,java,css,javafx,Java,Css,Javafx,我构建了一个基于Java Swing的游戏(Reversi又名Otherlo,学生项目)。 通过菜单栏中的颜色选择器,我为用户提供了为背景、球场和球员选择不同颜色的可能性 this.menu_bar.bg_color.addActionListener(e -> { Color buffer = colors[0]; colors[0] = JColorChooser.showDialog(null, "Hintergrundfarbe", colors[0]);

我构建了一个基于Java Swing的游戏(Reversi又名Otherlo,学生项目)。 通过菜单栏中的颜色选择器,我为用户提供了为背景、球场和球员选择不同颜色的可能性

this.menu_bar.bg_color.addActionListener(e -> { Color buffer = colors[0];
        colors[0] = JColorChooser.showDialog(null, "Hintergrundfarbe", colors[0]);
        if (colors[0] == null)
            colors[0] = buffer;
        else
            this.frame.change_colors(colors);});
使用过的颜色保存在数组“colors”中,并通过一些方法调用设置choosen颜色

void change_colors(Color[] colors)
{
    this.colors = colors;
    this.setBackground(colors[1]);
}
一切正常

现在我正在构建一个JavaFX等价物。我不使用FXML或场景生成器,但我尝试使用CSS文件

//.java
this.getStylesheets().add("Fx_GUI/Style.css");
this.getStyleClass().add("cell");

//.css
.cell
{
   -fx-background-color: rgb(34, 139, 34);
}
我的问题是:是否有一种基于css的方法可以获得相同的效果,为我的组件设置一个单独的颜色集?例如,使用.css中的变量或类似的东西?

您可以使用(向下滚动到颜色方块之外,以描述查找到的颜色):

CSS:

.root{
/*默认值*/
-细胞背景:rgb(34,139,34);
}
.细胞{
-fx背景色:-单元格背景;
}
爪哇:

this.getStylesheets().add("Fx_GUI/Style.css");
this.getStyleClass().add("cell");

// ...

int r = ... ;
int g = ... ;
int b = ... ;
this.setStyle(String.format("-cell-background: rgb(%d, %d, %d);", r, g, b));