I'm learning about JDBC with GUI. I can do that the GUI display the data in SQL one by one. Then i want to display the data in table just like the result when i execute in SQL. I saw that many people use two Vector to add data to JTable. I wonder is there anything else apart from Vector that I can do to add data to JTable.I really want to add some images in my post but i can't so sorry if it's uncovinient for everyone. Thanks for reading.
1 Answer
I wonder is there anything else apart from Vector that I can do to add data to JTable.
The DefaultTableModel uses Vectors because it makes the TableModel dynamic. That is you can easily add or remove rows/columns from the model.
If you don't want to use a Vector then you can create a custom TableModel to store the data any way that you want.
Check out Row Table Model. It gives an example
- of how to create a custom TableModel using an ArrayList for the data
- of to write a generic TableModel that is reusable
2 Comments
aU sUd
Does ArrayList is easy to add, remove or edit the data in JTable ?
camickr
@aUsUd, The TableModel controls whether you can add/remove rows of data or edit the data. Read the Swing tutorial on
Creating a TableModel. I provided a link to the tutorial which explains in detail how a JTable works.