问题
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.
回答1:
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
}
});
来源:https://stackoverflow.com/questions/14236666/how-to-get-current-treeitem-reference-which-is-expanding-by-user-click-in-javafx