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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -