2016-12-26 1 views
0

InstrumentクラスとControllerクラスを作成しました。私はbindingBidirectional()メソッドで大きな問題があります。それは私がプロパティAmountPropertyとバインドしようとしているときに私にエラーを与えるInstrumentクラスです。[JavaFx]このバインディングで何が問題になっていますか?

amount.valueProperty().bindBidirectional(instrument.amountProperty()); 

私はここで間違っていますか?

Controller class

public class Controller implements Initializable{ 

@FXML 
private ComboBox<Integer> amount = new ComboBox<>(); 
ObservableList<Integer> amountOptions = FXCollections.observableArrayList(0, 5, 10, 25, 50); 

Instrument instrument = new Instrument(); 

@Override 
public void initialize(URL location, ResourceBundle resources) { 

    amount.getItems().addAll(amountOptions); 
    //THIS ONE IS NOT WORKING 
    amount.valueProperty().bindBidirectional(instrument.amountProperty()); 

}} 

そしてInstrumentクラス:

public class Instrument { 

private IntegerProperty amount = new SimpleIntegerProperty(); 

public int getAmount() { 
    return amount.get(); 
} 

public IntegerProperty amountProperty() { 
    return amount; 
} 

public void setAmount(int amount) { 
    this.amount.set(amount); 
} 
} 
+0

あなたはどのようなエラーを取得していますか? – assylias

+0

http://stackoverflow.com/questions/24889638/javafx-properties-in-tableviewを参照してください。 –

+0

java:bindBidirectional(javafx.beans.property.IntegerProperty)の適切なメソッドが見つかりません メソッドjavafx.beans.property.Property.bindBidirectional (javafx.beans.property.Property.Property )は適用されません (引数の不一致; javafx.beans.property.IntegerPropertyはjavafx.beans.property.Property に変換できません) メソッド – Rocky3582

答えて

1

IntegerPropertyProperty<Number>のではなく、Property<Integer>の実装です。コンボボックスのvaluePropertyProperty<Integer>です。したがって、型が一致しないため、2つの間で双方向に直接バインドすることはできません。

あなたはどちらかComboBox<Number>であるためにあなたのコンボボックスを変更、またはIntegerProperty.asObject()を使用して、双方向IntegerPropertyにバインドされているObjectProperty<Integer>を作成することができます。

amount.valueProperty().bindBidirectional(
    instrument.amountProperty().asObject()); 
+0

あなたに感謝しています。今私は理解しています:) – Rocky3582

+0

@ Rocky3582あなたの質問に答えたら正しいとマークしてください –

関連する問題