我如何可以填補與ChoiceBox
例如我的自定義課程中的StringProperty
?與自定義屬性灌裝ChoiceBox JavaFX中
我只是在SceneBuilder中設計了一個ChoiceBox
,我有一個Person
類與我的數據。
public class Person{
private final StringProperty firstName;
public Person(){
this(null);
}
public Person(String fname){
this.firstName = new SimpleStringProperty(fname);
}
public String getFirstName(){
return this.firstName.get();
}
public void setFirstName(String fname){
this.firstName.set(fname);
}
public StringProperty firstNameProperty(){
return this.firstName;
}
}
在主類中,我有:
private ObservableList<Person> personList = FXCollections.observableArrayList();
this.personList.add(new Person("Human1"));
RootController controller = loader.getController();
controller.setChoiceBox(this);
public ObservableList<Person> getPersonList(){
return this.personList;
}
而且在我的控制器:
public class RootController {
@FXML
private ChoiceBox personBox;
public RootController(){
}
@FXML
private void initialize(){
}
public void setChoiceBox(App app){
personBox.setItems(app.getPersonList());
}
}
但這個代碼由函數名(?)或類似的東西填補我ChoiceBox。 我怎麼能與firstName屬性補嗎?
我完全@fabian但對我來說,問題是爲什麼以及何時一個人的名字真正的改變?編輯:給予好評的提示 – SSchuette