如何像 String
一样在 JavaFX 中使用 BigInteger
作为属性用作 SimpleStringProperty
?
最佳答案
没有BigIntegerProperty
在 JavaFX(或任何 BigInteger
属性实现)中,但您可以使用 ObjectProperty<T>
作为ObjectProperty<BigInteger>
:
ObjectProperty<BigInteger> bigIntProp = new SimpleObjectProperty<>();
此属性存储一个 BigInteger
实例,可以被监听和绑定(bind)。
示例
安Application
使用此类型的地方,它绑定(bind)到 TextArea
的文本:
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
BorderPane root = new BorderPane();
ObjectProperty<BigInteger> bigIntProp = new SimpleObjectProperty<>();
bigIntProp.addListener((obs, oldval, newval) -> System.out.println(newval));
TextArea ta = new TextArea();
bigIntProp.bind(Bindings.createObjectBinding(() ->
(!ta.getText().isEmpty()) ? new BigInteger(ta.getText()) : BigInteger.ZERO
, ta.textProperty()));
root.setCenter(ta);
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
关于java - JavaFX 中的 BigInteger 属性是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42084983/