本文介绍了如何获得JavaFx 2中用户单击扩展的当前TreeItem引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个JavaFx 2情况下,我有一个TreeView,它最初以一定深度折叠.我要实现的目标是,当通过用户单击扩展一个节点时,将发生一个操作来修改该treeitem属性/值.

In one JavaFx 2 case, i have a TreeView, which is collapsed at certain depth initially. What i'm aiming to achieve is that when one node is being expanded by user click, an action will happend to modified that treeitem property/values.

问题是我不确定如何引用该树项.我在每个treeitem expanedProperty上添加了一个侦听器,但是在该ChangeListner方法中,我只能获取旧值/新值,无法引用更改事件起源的树项.

the problem is that i'm not sure how to refer to that treeitem. I add a listener on each treeitem expanedProperty, but in that ChangeListner method, i can only get old/new values, can't refer back to the treeitem that change event originates.

有人可以帮忙吗?非常感谢.

Can someone help? Thanks a lot.

推荐答案

是的.试试这个:

treeItem.expandedProperty().addListener(new ChangeListener<Boolean>() {
    @Override
    public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
        System.out.println("newValue = " + newValue);
        BooleanProperty bb = (BooleanProperty) observable;
        System.out.println("bb.getBean() = " + bb.getBean());
        TreeItem t = (TreeItem) bb.getBean();
        // Do whatever with t
    }
});

这篇关于如何获得JavaFx 2中用户单击扩展的当前TreeItem引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 21:13