JavaFX bidirectional binding of two different, non-String, ListProperty

天大地大妈咪最大 提交于 2019-12-11 05:17:27

问题


I need to bind together two ListProperties:

ObservableList<Data<Number, Number>>    chartDataList       = FXCollections.observableArrayList();
ListProperty<Data<Number, Number>>      chartDataProperty   = new SimpleListProperty<>(this, "chartData", chartDataList);
ObservableList<Point2D>                 observableData      = FXCollections.observableArrayList();
ListProperty<Point2D>                   dataProperty        = new SimpleListProperty<>(this, "Data", observableData);

chartDataList will be used to display a LineChart, while the other (data) will be used in the rest of my program. chartDataProperty is not really needed (but for binding), because LineChart uses just chartDataList.

Note: binding needs to be bidirectional because I have means to manually drag the points on the LineChart using mouse.

I didn't find a direct way to handle this; only conversion seems to be to/from String (or ListProperty<String>). I could use that, with man-in-the-middle ListProperty<String>, but it looks very inefficient.

Otherwise I need to resort to ChangeListner usage, manually handling all possible cases.

Please tell me I have some better choice.

来源:https://stackoverflow.com/questions/24479506/javafx-bidirectional-binding-of-two-different-non-string-listproperty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!