java - JavaFX property change listener: null newValue -


i have cuttingoperationcombobox combobox , method changes items , value of combobox:

public void changeglass(glass newglass) {     observablelist<operation> list = new filteredlist<operation>(productglasscuttingui.this.operationsdb.getoperationslist(), operation -> operation.getoperationtype().tostring().equals("re") &&             operation.getglassthickness() == newglass.getglassthickness());      if(!list.contains(this.cuttingoperationcombobox.getvalue()))         cuttingoperationcombobox.setvalue(list.get(0));     cuttingoperationcombobox.setitems(list); } 

i have change listener added cuttingoperationcombobox.valueproperty(). fired first time cuttingoperationcombobox.setvalue(list.get(0)); , here fine. when cuttingoperationcombobox.setitems(list); fires change listener, newvalue in null although list not empty. happens when combobox visible. tobe more precise: cuttingoperationcombobox displayed in treeview part of treecell graphics. long tree view node containing combobox collapsed ok, when expand node , combobox shows, above problem appears. know doing wrong?

whenever call setitems() of combobox (or other controls involving list of items), combobox (or respective control) clear selection. believe behavior caused underlying selection model, , believe desired behavior use-cases.

without knowing achieving, it's hard give exact solution. if want retain value after setting new list, might need keep copy of old selection item, , manually set in after setitems(). if don't want changelistener respond setitems(), either check null newvalue in listener, or keep boolean flag somewhere tell listener particular call triggered setitems().


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -