小编det*_*ef1的帖子

不同属性的双向绑定

我只是试图绑定一个Integer和一个String属性.经过一些谷歌搜索后,应该可以使用以下两种方法之一:

  1. public static void bindBidirectional(Property stringProperty,
    Property otherProperty ,StringConverter converter)

  2. public static void bindBidirectional(Property stringProperty,
    Property otherProperty ,java.text.Format format)

不幸的是,这似乎对我不起作用.我究竟做错了什么?

import java.text.Format;

import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.util.converter.IntegerStringConverter;

public class BiderectionalBinding {

    public static void main(String[] args) {
        SimpleIntegerProperty intProp = new SimpleIntegerProperty();
        SimpleStringProperty textProp = new SimpleStringProperty();

        Bindings.bindBidirectional(textProp, intProp, new IntegerStringConverter());

        intProp.set(2);
        System.out.println(textProp);

        textProp.set("8");
        System.out.println(intProp);    
    }
}
Run Code Online (Sandbox Code Playgroud)

java binding properties bidirectional javafx-2

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

bidirectional ×1

binding ×1

java ×1

javafx-2 ×1

properties ×1