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

时间:2016-05-13 06:09:24

标签: javafx javafx-2 javafx-8

问题描述 - 在我的应用程序中,我需要恢复tile窗格(或任何其他控件)的颜色,但我找不到任何属性/函数。

我使用平铺窗格显示颜色样本,并在其点击事件中我想要它的背景颜色。

我想要的是:我希望在其点击事件中获得控件的背景颜色

1 个答案:

答案 0 :(得分:2)

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 :)

希望有所帮助

相关问题