在自定义TreeItem属性更改上更新TreeView

编程入门 行业动态 更新时间:2024-10-20 07:42:38
本文介绍了在自定义TreeItem属性更改上更新TreeView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我扩展了TreeCell和TreeItem类。 MyTreeItem包含一个自定义属性,我在MyTreeCell中使用它来渲染图形/字体等。问题是当我设置MyTreeCell.customProperty我不知道如何使TreeView / Cell重绘。

I have extended TreeCell and TreeItem class. MyTreeItem contains a custom property which I use inside MyTreeCell to render graphics/font etc. The problem is when I set MyTreeCell.customProperty I'm not sure how to make the TreeView/Cell redraw.

例如:

public class MyTreeItem extends TreeItem { Object customProperty public void setCustomProperty(Object customProperty) { this.customProperty = customProperty // how to fire a change event on the TreeView? } }

对解决方案或(缺乏)设计的任何评论方法赞赏。

Any comments on the solution or (lack of) design approach appreciated.

推荐答案

至少有两种方法(不包括将值归零的黑客,如评论中所建议的那样)

There are at least two approaches (not including the hack of nulling the value, as suggested in the comments)

一种是在设置自定义属性时手动触发TreeModificationEvent,即在setCustomProperty中:

One is to manually fire a TreeModificationEvent when setting the custom property, that is in your setCustomProperty:

public class MyTreeItem extends TreeItem { Object customProperty public void setCustomProperty(Object customProperty) { this.customProperty = customProperty TreeModificationEvent<T> ev = new TreeModificationEvent<>(valueChangedEvent(), this); Event.fireEvent(this, ev); } }

另一种方法是将自定义属性设为真实属性,让感兴趣的各方(你的自定义TreeCell)听取该属性的变化。有关如何实现(和重新连接)侦听器的示例,请查看DefaultTreeCell如何处理TreeItem的graphicProperty。

Another is to make the custom property a "real" property and let interested parties (f.i. your custom TreeCell) listen to changes of that property. For an example of how to implement (and re-wire) the listener have a look at how DefaultTreeCell handles the graphicProperty of a TreeItem.

选择哪个取决于您的上下文:第一个确保通知TreeModificationEvents的所有侦听器,第二个允许实现一般TreeCell,使treeItem的属性(工厂)可视化。

Which to choose depends on your context: the first makes sure that all listeners to TreeModificationEvents are notified, the second allows to implement a general TreeCell taking a property (factory) of the treeItem to visualize.

更多推荐

在自定义TreeItem属性更改上更新TreeView

本文发布于:2023-10-27 03:13:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532146.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   属性   TreeItem   TreeView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!