java - Does there exist a fix / best-practice approach for sorting JTables with dynamic model -
i found the following question regarding sorting jtable whichs model not "static" elements may added it, automatically updating sort order. accepted answer states:
so, changed
firetablecellupdated(row, col);
to
firetablerowsupdated(0, data.size() - 1);
and sorts properly, upon data changes, , selection preserved.
since question on 5 years old, java 8 , co. happening, wanted ask if there new / better solution achieve sorting.
in model implementing abstracttablemodel
call
firetablecellupdated(newrowid, newcolid);
when new item added.
the code in ui looks following:
jtable table = new jtable(); table.setmodel(mymodel); // mymodel declared somewhere above table.setautocreaterowsorter(true); table.getrowsorter().setsortkeys(arrays.aslist(new rowsorter.sortkey(0, sortorder.ascending)));
do have go solution proposed in other question or there "better" / best-practice way this?
Comments
Post a Comment