0
FXMLでxamlと同じようにバインドして、コントローラにクラスvaribaleをバインドすることは可能ですか?私は何をやっていることは次のとおりです。FXML:コントローラへのバインド
FXML
<ComboBox fx:id="searchField"
HBox.hgrow="ALWAYS" editable="true" />
<GridPane hgap="5" vgap="5">
<Label text="Nom" />
<Label text="$selecteClient.name"
GridPane.columnIndex="1" />
<Label GridPane.rowIndex="1" text="tél" />
<Label text="$electedClient.phoneNumber"
GridPane.rowIndex="1" GridPane.columnIndex="1" />
<GridPane/>
のcontroler:
private final List<Client> clients = FXCollections.observableArrayList(ImportingDataService.importClients());
@FXML
private Client selectedClient;
@FXML
private ComboBox<Client> searchField;
@Override
public void initialize(URL location, ResourceBundle resources) {
// Set appDtat client id so it refreshes when client is changed
this.appState.clientViewClientIDProperty().addListener((obs, oldValue, newValue) -> {
selectedClient = ImportingDataService.importClient(newValue.longValue());
});
// Set up combo box
setUpComboBox();
}
private void setUpComboBox() {
searchField.getItems().addAll(clients);
UtilService.autoCompleteComboBoxPlus(searchField, (typedText, client) -> client.getName().contains(typedText));
// Handle selecting clients
searchField.getSelectionModel().selectedItemProperty().addListener((obs, oldValue, newValue) -> {
selectedClient = ImportingDataService.importClient(newValue.getId());
});
}
マイClient
クラスString
フィールドname
とphoneNumber
を持つクラスです。 ImportingDataService.importClient
はデータベースからデータをインポートするためのもので、うまく動作します(ブレークポイントを設定してチェックしました)。問題は、selectedClient
が変更されている間にComboBox
の選択を変更したときにクライアントLabel
が更新されない理由がわかりません。私は間違って何をしていますか?
これは素晴らしい完全な答えですが、誤植を修正するだけで動作します。観察可能なオブジェクトは必要ありません。ありがとう。 –
私が言ったことを取り戻します。動いていない。実際には、他の属性にバインドされたラベルをいくつか追加しますが、これはコンボボックス選択モデルを使用することになります。このようにして、オブザーバブルオブジェクトなしで動作します。それ以外の賢さはありません。 –