将IntegerProperty绑定到DoubleProperty [英] Bind IntegerProperty to DoubleProperty

查看:41
本文介绍了将IntegerProperty绑定到DoubleProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在IntegerProperty和DoubleProperty之间创建双向绑定.转换器函数很容易编写以创建两个值之间的映射,但是我找不到解决方法.我正在寻找功能类似于StringConverter但具有通用参数的东西.

I would like to create a bidirectional binding between an IntegerProperty and a DoubleProperty. A converter function would be easy to write to create the mapping between the two values, but I cannot find a way to do it. I am looking for something similar in functionality to StringConverter, but with generic parameters.

在JavaFX中有没有办法做到这一点?

Is there a way to do it in JavaFX?

推荐答案

由于它们都是Property<Number>的实现,因此应该可以使用:

Since they're both implementations of Property<Number> it should just work:

    DoubleProperty d = new SimpleDoubleProperty();
    IntegerProperty i = new SimpleIntegerProperty();
    d.bindBidirectional(i);

这篇关于将IntegerProperty绑定到DoubleProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆