Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Binding in TreeView vs TableView

Shant BozianNov 7 2012
Hello,

I am wondering why isn't TreeView designed like TableView with respect to the binding with the underlying data.

In the sense that, given a Person type with 'name' StringProperty, in the case of TableView, when I pass the 'name' property (as an ObservableValue) through the cell value factory, TableView guarantees for me that:
- whenever the 'name' property changes, the change is also reflected in the corresponding cell in the table
- whenever the corresponding cell is edited in the table, the change is also reflected in the 'name' property

Which means that the TableView design guarantees a sort of bidirectional binding between the underlying data and the displayed cell.


Things seem to be different in TreeView, which apparently doesn't offer an API to pass an ObservableValue.

Example 14-3 at the following link, shows how to implement editing in the tree:
http://docs.oracle.com/javafx/2/ui_controls/tree-view.htm#

When I edit an item, the tree displays the modified item, but nothing updates the underlying data model (i.e. whenever I edit an employee name, I expect the 'name' property in Employee to see the change, but it doesn't).

So to achieve that, I couldn't other than do the binding myself as follows:
treeItem.valueProperty().bindBidirectional(employee.nameProperty());
Is this a good practice, or can TreeView somehow handle this internally?

Thank you
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 5 2012
Added on Nov 7 2012
0 comments
940 views