简体   繁体   中英

Using JTable to display ResultSet

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.

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

  1. of how to create a custom TableModel using an ArrayList for the data
  2. of to write a generic TableModel that is reusable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM