2016-12-09 7 views
1

choiceboxの表示にオブジェクトのプロパティ値を設定するにはどうすればよいですか?ここでChoiseboxのvalueプロパティをdb外のオブジェクトから設定する

@FXML 
private ChoiceBox<LuggageBrand> brandSelector; 

私はLuggageBrandオブジェクトとchoiceboxを充填していていることがわかりますが、今のアプリケーションに表示されている値は、オブジェクトの.toString()です。

どうすればいいですか、ちょっと、このプロパティを使ってchoiceboxに表示してください。 ChoiceBoxにコンバータを設定し

答えて

1

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... 

} 
+0

ありがとう!それは働いた:D – CodifyDan

関連する問題