java - JTable not updating when model updates -
ok, have read on this, i'm still confused. have jtable custom table model stores data in arraylist. displays fine. however, when want add row, add object arraylist, call firetablerowsinserted(...). however, table not refresh.
public main() { initcomponents(); current_map = new map(); current_map.authors.add(new author("new author")); author_model = new authormodel(current_map.authors); jtable1.setmodel(new authormodel(current_map.authors)); <---this mistake } ... private void jbutton1actionperformed(java.awt.event.actionevent evt) { author_model.authors.add(new author("new author")); author_model.firetablerowsinserted(author_model.authors.size(), author_model.authors.size()); }
the above code main jframe. not sure go here.
i'm lost right now.
the table initialized with:
jtable1.setmodel(new authormodel(current_map.authors));
but when button clicked, modify variable author_model:
author_model.authors.add(new author("new author"));
the initialization of table should be
jtable1.setmodel(author_model);
you should respect java naming conventions, , choose better names variables.
Comments
Post a Comment