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!

FXML TableView bind to nested object property

936814Aug 2 2012 — edited Jul 12 2013
Hi,
I need to bind a TableColumn of a TableView<MyModel> to a property of an object like that

/****************** Nested Class **********************/
public class MyStatisticsBean {
private final DoubleProperty average = new SimpleDoubleProperty(0);

public double getAverage() {
return average.get();
}

public void setAverage(double value) {
if (value != average.get())
average.set(value);
}

public DoubleProperty averageProperty() {
return average;
}
}

/****************** Model **********************/
public class MyModel {
...

private ObjectProperty<MyStatisticsBean> statistics = new SimpleObjectProperty<MyStatisticsBean>(
this, "statistics");

public final MyStatisticsBean getStatistics() {
return statistics.get();
}

public final void setStatistics(MyStatisticsBean value) {
statistics.set(value);
}

public final ObjectProperty<MyStatisticsBean> statisticsProperty() {
return statistics;
}

...
}

I've tried the following FXML code but it doesn't work:


/****************** FXML TableView **********************/

<TableView fx:id="myTable">
<columns>
...
<TableColumn text="Avg">
<cellValueFactory>
<PropertyValueFactory property="statistics.average" />
</cellValueFactory>
</TableColumn>

...
</columns>
</TableView>


How can I do that?

Thank you in advance.

Andrea

Edited by: atasca on Aug 2, 2012 10:11 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 9 2013
Added on Aug 2 2012
8 comments
3,950 views