Reputation: 603
I'm trying to do an MVC app with java, and i want to have a window with a JTable in it.
Apparently that's the component that can display a listbox with multicolumns, and i want to fill it with instances of different classes that implements the same interface.
The only thing i was able to do for now is to initialize my JTable with a Object[][] and an array of string for the columns name.
But this doesn't feel right. Everytime something changes in my model which contains the original list of objects, i would have to reload everything in my JTable...
Is there a way to simply bind a Vector into a JTable so that it automatically update when the Vector is modified ?
Thanks in advance for your answer.
Upvotes: 0
Views: 82
Reputation: 324197
Everytime something changes in my model
You should have a separate model. You should be changing the TableModel
Is there a way to simply bind a Vector into a JTable so that it automatically update when the Vector is modified ?
You should NOT be updating the Vector.
Instead you should be updating the TableModel. Then the TableModel will notify the JTable of the changes so the table can be repainted.
This is the way Model-View-Controller (MVC) works for all Swing components.
Upvotes: 1