【问题标题】:How to get Background color of tile pane in Javafx?如何在 Javafx 中获取平铺窗格的背景颜色?
【发布时间】:2016-05-13 06:09:24
【问题描述】:

问题描述 - 在我的应用程序中,我需要恢复平铺窗格(或任何其他控件)的颜色,但我没有找到任何属性/功能。

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

我想要什么:我想在其点击事件上获得控件的背景颜色

【问题讨论】:

标签: javafx javafx-2 javafx-8


【解决方案1】:

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

希望对你有帮助

【讨论】:

  • 谢谢先生,但我通过创建带有背景颜色属性的自定义控件解决了这个问题
  • 获得最后一个填充可能更好,因为它是最后一个要渲染的(根据 javafx.scene.layout.Background 的文档“每个定义的 BackgroundFill 按顺序渲染”)。所以应该是b.getFills().get(b.getFills().size() - 1).getFill() 而不是b.getFills().get(0).getFill()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-15
  • 1970-01-01
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多