java - JTable cell losing value when it's clicked to open a JComboBox -


got current project going on , need set cells column in jtable jcomboboxes. items same rows , extracted sql server table. when program runs, fills whole jtable values sql server table. ok @ point when user clicks column show jcombobox , items show up, the value on cell overwritten jcombobox. wanted happen opening jcombobox values , "suggesting" user last value in cell (the 1 disappeared), dropping down , selecting said value.

is there way doing easily?

this how i'm adding items jcomboboxes

tablecolumn col_cod_tipo_verba = jtab_verba.getcolumnmodel().getcolumn(3); jcombobox box_tab_tipo_verba = new jcombobox(); resultset rs = glob.conecta_sql().preparestatement("select * tab_tipo_verba").executequery(); while (rs.next()) { box_tab_tipo_verba.additem(rs.getstring(1)); } col_cod_tipo_verba.setcelleditor(new defaultcelleditor(box_tab_tipo_verba));

you can override method

component gettablecelleditorcomponent(jtable table, object value,                                       boolean isselected,                                       int row, int column) 

in call col_cod_tipo_verba.setcelleditor(new defaultcelleditor(box_tab_tipo_verba)); , after super.gettablecelleditorcomponent use value set in editor


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -