java - How to populate a ChoiceBox with objects from a List -


i wan't populate choicebox list<object>. object has name field wan't use choice text. of course need know object user has selected in order pass correct data.

fxml controller:

public void initialize(url fxmlfilelocation, resourcebundle resources) {     universitiesservice uniservice = new universitiesserviceimpl();     list<university> unilist = uniservice.getuniversitieslist();     //unichoicebox.setitems(); need guidance here } 

university entity:

private string universityname; private string universityurl; private string[] universitydatanames;  //getters setters 

just do

unichoicebox.getitems().setall(unilist); 

if need configure display (i.e. if tostring() method in university doesn't give text need), add converter:

unichoicebox.setconverter(new stringconverter<university>() {     @override     public string tostring(university uni) {         return uni.getuniversityname();     }     @override     // not used...     public university fromstring(string s) {         return null ;     } }); 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -