java - JComboBox<BeanObject> not displaying edited values -
i have jtable, first column uses jcombobox editor. combobox model contains data objects fetched sql database. if manually enter value inside combobox , leave editor, entered value lost. doens't happen if value selected popup, or if jcombobox's model instantiated simple strings instead of bean objects. note need add row dinamically, seems irrelevant since issue appears both in default row , in added rows.
this working netbeans sample project reproduces issue: https://drive.google.com/open?id=0b89fss48-yy4v09yrvozrzjgmkk
here relevant code:
public newjframe() { initcomponents(); //bean objects used populate combobox: item item1 = new item("one", 1); item item2 = new item("two", 2); item item3 = new item("three", 3); jcombobox<item> combobox = new jcombobox<>(new item[]{item1, item2, item3}); combobox.seteditable(true); defaultcelleditor defaultcelleditor = new defaultcelleditor(combobox); defaultcelleditor.setclickcounttostart(1); jtable1.getcolumnmodel().getcolumn(0).setcelleditor(defaultcelleditor); } private void addrowbuttonactionperformed(java.awt.event.actionevent evt) { ((defaulttablemodel) jtable1.getmodel()).addrow(new object[]{null, null}); }
update: when jcombobox in table populated via model instead of constructor this,
items = new item[]{item1, item2, item3}; jcombobox<item> combobox = new jcombobox<>(); combobox.setmodel(new defaultcomboboxmodel<>(items));
a manually inserted value kept displayed, if no selection has been made before; is, if first select choice , edit choice, when leaving combobox selected item reappears. none of reported behaviours occur in jcombobox outside table, led me think it's related celleditor.
update 2: here's bug report of issue year 2000! said solved far solved after 15 years.
Comments
Post a Comment