java - ChoiceBox not setting ObservableList in JavaFX -


i have choicebox in javafx application named choiceboxpizza.

in controller declare with:

@fxml  private choicebox choiceboxpizza; 

my function contains test data is:

private void fillchoiceboxpizza(){     try {         list<string> list = new arraylist<string>();         list.add("pizza a");         list.add("pizza b");         list.add("pizza c");         observablelist oblist = fxcollections.observablelist(list);         choiceboxpizza = new choicebox<>(oblist);     } catch (exception e) {         // todo auto-generated catch block         system.out.println(e.tostring());     }  } 

so should filled list. strange thing is, not exception , choicebox after call of method still empty.

is there mistake in logic?

replace line:

choiceboxpizza = new choicebox<>(oblist); 

with one, should work:

choiceboxpizza.setitems(oblist) 

you should not initialize element declared in .fxml file. here more broader explanation on how initialization process in javafx works.

hope helps


Comments

Popular posts from this blog

Google sheets equipment borrowing system -

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

c# - Convert type 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.IList<>' -