javafx - Select value from Object in ComboBox -


i have java object want edit using code. value want obj.getsizebetweenmessages() 10:

observablelist<integer> zoptionsm = fxcollections.observablearraylist(             obj.getsizebetweenmessages(), 90);         combobox<integer> zcombom = new combobox<>(zoptionsm);         zcombom.getselectionmodel().select(obj.getsizebetweenmessages());         zcombom.seteditable(true);         gpm.add(zcombom, 1, 1); 

for reason combobox empty , value object not displayed. give me idea i'm wrong?

if getsizebetweenmessages() method returning int, (not integer), you're relying on autoboxing both when pass result fxcollections.observablearraylist(...) , zcombom.getselectionmodel().select(...). in first case, works, because there no appropriate observablearraylist(...) method taking int, in second case there select(...) method accepting int, , 1 gets invoked. if getsizebetweenmessages() returns 10, trying select item @ position 10 (not item 10 itself), , since that's out of bounds nothing gets selected.

the fix create integer object hand:

integer sizebetweenmessages = new integer(obj.getsizebetweenmessages()); observablelist<integer> zoptionsm = fxcollections.observablearraylist(             sizebetweenmessages, 90);         combobox<integer> zcombom = new combobox<>(zoptionsm);         zcombom.getselectionmodel().select(sizebetweenmessages);         zcombom.seteditable(true);         gpm.add(zcombom, 1, 1); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -