如何在 Javafx 中获取平铺窗格的背景颜色?

How to get Background color of tile pane in Javafx?

问题描述 - 在我的应用程序中,我需要取回拼贴窗格(或任何其他控件)的颜色,但我没有找到任何 property/function。

我使用 tile pane 来显示颜色样本,在它的点击事件中我想要它的背景颜色。

我想要的:我想在它的点击事件中获得控件的背景颜色

试试这个 ActionEvent 你可以做到这一点

handle(ActionEvent event){//suppose we are in the handle method
   Object o = event.getSource();
   if(o instanceof Region){
       Background b = ((Region)o).getBackground();
       Paint p = b.getFills().get(0).getFill();//paint is actually your color :)
       if(p instanceof Color){
          ((Color)p) //now you have a color :)

希望对您有所帮助