Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current TreeItem reference which is expanding by user click in JavaFx 2?

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.

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.

like image 510
Qishan Avatar asked Jan 09 '13 13:01

Qishan


1 Answers

Yes of course. Try this:

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
    }
});
like image 161
Uluk Biy Avatar answered Oct 11 '22 12:10

Uluk Biy