Java 从db外的对象设置Choisebox的值属性
如何为choicebox的显示设置对象的属性值Java 从db外的对象设置Choisebox的值属性,java,javafx,Java,Javafx,如何为choicebox的显示设置对象的属性值 @FXML private ChoiceBox<LuggageBrand> brandSelector; @FXML 私人选择框品牌选择器; 在这里,您可以看到我正在用LuggageBrand对象填充选择框,但是现在应用程序上显示的值是对象的.toString() 我怎么能说,嘿,请使用此属性在选择框上显示 在选择框上设置转换器: public void initialize() { brandSelector.setCo
@FXML
private ChoiceBox<LuggageBrand> brandSelector;
@FXML
私人选择框品牌选择器;
在这里,您可以看到我正在用LuggageBrand
对象填充选择框,但是现在应用程序上显示的值是对象的.toString()
我怎么能说,嘿,请使用此属性在选择框上显示 在
选择框上设置转换器:
public void initialize() {
brandSelector.setConverter(new StringConverter<LuggageBrand>() {
@Override
public String toString(LuggageBrand luggageBrand) {
// whatever logic you need here to turn the LuggageBrand object to a string:
String value = luggageBrand.getXXX();
return value ;
}
@Override
public LuggageBrand fromString(String text) {
// this method is not used by the ChoiceBox, so you can just
return null ;
}
});
// other initialization code...
}
public void initialize(){
brandSelector.setConverter(新的StringConverter(){
@凌驾
公共字符串到字符串(LuggageBrand LuggageBrand){
//将LuggageBrand对象转换为字符串所需的任何逻辑:
字符串值=luggageBrand.getXXX();
返回值;
}
@凌驾
公共行李品牌fromString(字符串文本){
//ChoiceBox不使用此方法,因此您可以
返回null;
}
});
//其他初始化代码。。。
}