0

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 1

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Does ArrayList is easy to add, remove or edit the data in JTable ?
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.