String
のようなJavaFXでプロパティとしてBigInteger
を使用する方法は、SimpleStringProperty
として使用されますか?JavaFXのBigIntegerプロパティとは何ですか?
4
A
答えて
1
ビルトイン一切のBigInteger PropertyクラスJavaでSimpleStringPropertyクラスのようにはありません。
私はSimpleBigIntegerPropertyを作成しました。これは組み込みのプロパティクラスと同じように使用できます。
import java.math.BigInteger;
import javafx.beans.property.SimpleObjectProperty;
/**
*
* This class provides a full implementation of a {@link Property} wrapping an
* arbitrary {@code BigInteger}.
*/
public class SimpleBigIntegerProperty extends SimpleObjectProperty<BigInteger>{
private static final Object DEFAULT_BEAN = null;
private static final String DEFAULT_NAME = "";
private final Object bean;
private final String name;
/**
* {@inheritDoc}
*/
@Override
public Object getBean() {
return bean;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
}
/**
* The constructor of {@code BigIntegerProperty}
*/
public SimpleBigIntegerProperty() {
this(DEFAULT_BEAN, DEFAULT_NAME);
}
/**
* The constructor of {@code BigIntegerProperty}
*
* @param initialValue
* the initial value of the wrapped value
*/
public SimpleBigIntegerProperty(BigInteger initialValue) {
this(DEFAULT_BEAN, DEFAULT_NAME, initialValue);
}
/**
* The constructor of {@code BigIntegerProperty}
*
* @param bean
* the bean of this {@code BigIntegerProperty}
* @param name
* the name of this {@code BigIntegerProperty}
*/
public SimpleBigIntegerProperty(Object bean, String name) {
this.bean = bean;
this.name = (name == null) ? DEFAULT_NAME : name;
}
/**
* The constructor of {@code BigIntegerProperty}
*
* @param bean
* the bean of this {@code BigIntegerProperty}
* @param name
* the name of this {@code BigIntegerProperty}
* @param initialValue
* the initial value of the wrapped value
*/
public SimpleBigIntegerProperty(Object bean, String name, BigInteger initialValue) {
super(initialValue);
this.bean = bean;
this.name = (name == null) ? DEFAULT_NAME : name;
}
}
例1:
簡単な例、
SimpleBigIntegerProperty bigInteger = new SimpleBigIntegerProperty(BigInteger.valueOf(123456789));
System.out.println(bigInteger.getValue());
例2: ObservableList例では、
private final ObservableList<Person> data = FXCollections.observableArrayList(
new Person("Jon Skeet", BigInteger.valueOf(123456789)),
new Person("Michael Brown", BigInteger.valueOf(987654321))
);
ここでPersonクラス(人名と年齢属性を持つ)は、
public class Person {
protected SimpleStringProperty personName;
protected SimpleBigIntegerProperty ageInSeconds;
public Person() {
this.personName = null;
this.ageInSeconds = null;
}
public Person(String person_name, BigInteger age_in_seconds) {
this.personName = new SimpleStringProperty(person_name);
this.ageInSeconds = new SimpleBigIntegerProperty(age_in_seconds);
}
public void setPersonName(String person_name) {
this.personName = new SimpleStringProperty(person_name);
}
public void setAgeInSeconds(BigInteger age_in_seconds) {
this.ageInSeconds = new SimpleBigIntegerProperty(age_in_seconds);
}
public String getPersonName() {
return this.personName.getValue();
}
public BigInteger getAgeInSeconds() {
return this.ageInSeconds.getValue();
}
}
2
ありJavaFXのにはBigIntegerProperty
(または任意のBigInteger
プロパティの実装は)ありませんが、あなたはObjectProperty<BigInteger>
としてObjectProperty<T>
を使用することができます。
ObjectProperty<BigInteger> bigIntProp = new SimpleObjectProperty<>();
このプロパティストアは1 BigInteger
インスタンスと聞いてバインドすることができます。
例TextArea
のテキストにバインドされているこのタイプが使用されている
Application
、:
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);
}
}
関連する問題
- 1. javafxシーンオブジェクトのルートノードとは何ですか?
- 2. schema.orgのnameプロパティとは何ですか?
- 3. C++/CLIのプロパティとは何ですか?
- 4. Groovyの 'プロパティ'とは何ですか?
- 5. のJavaFX:プロパティ
- 6. ロンボクのJavaFXプロパティ
- 7. ember.jsの '[]'プロパティと '@each'プロパティの違いは何ですか?
- 8. XMLプロパティxmlns:appとは何ですか?
- 9. .NET Control.Marginプロパティとは何ですか?
- 10. C3.JS color.patternプロパティとは何ですか?
- 11. JavaFXでScrollBarを使用するルールとは何ですか?
- 12. Javascript:関数のプロパティとは何ですか?その意味は何ですか?
- 13. BigDecimal/BigIntegerをProtocolBuffersにシリアライズする最良の方法は何ですか
- 14. JavaFX CSSのプロパティとセレクタのベストプラクティス
- 15. BigIntegerは効率的ですか?
- 16. あなた自身の言葉で、JavaFXとJavaアプレットは何ですか?彼らの違いは何ですか?
- 17. EntityDataSourceのselectプロパティの "it"とは何ですか?たとえば
- 18. JavaFX:ペインへのトラブルバインディングのプロパティ
- 19. ProgressBarコントロールのLargeChangeプロパティとSmallChangeプロパティは何をするのですか?
- 20. Javascript hasOwnPropertyのプロパティは何ですか?
- 21. ポリマーの "is"プロパティは何ですか?
- 22. スイングコンポーネントの名前プロパティは何ですか?
- 23. nullにすることができ、オブジェクトのJavaFXのプロパティにバインド
- 24. TFSのWorkItemクラスのLinksプロパティとWorkItemLinksプロパティの違いは何ですか?
- 25. @JsonIgnoreのプロパティと注釈のないプロパティの違いは何ですか?
- 26. Android WebViewClientのプロパティで "isForMainFrame"リクエストとは何ですか?
- 27. javascriptのcurrentTargetプロパティとtargetプロパティの正確な違いは何ですか?
- 28. 依存関係プロパティとWPFの添付プロパティの違いは何ですか?
- 29. Visual Studioの参照プロパティのエイリアスとは何ですか?
- 30. [プロパティ]の[バージョン]タブとWindows Vistaの対応は何ですか?
ObjectPropertyとSimpleObjectPropertyを使用しないのはなぜですか? – Puce
オブジェクトを割り当てるよりも別の型を作成する方が良いと思います。例えば、 'Object sum = 12 + 13;'のようにオブジェクトにintを代入することはできますが、 'int sum = 12 + 13;'が良いと思います。 –
基本的なプロパティの場合はそれが理にかなっています。そのため、JavaFXはそれらをすぐに提供します。 Stringには追加のメソッドがあるため、StringPropertyも意味を持ちます。ただし、プロパティに対して特別なメソッドを提供しない限り、カスタムプロパティタイプは通常は必要ありません。 – Puce