This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have noticed that most models for JTables use a multidimensional array to store the data for the table. For example:
This array cannot be resized automatically. Is there an easy way to use one of the classed in the Collections Framework to store the data in the model so that I can add rows to the table without worrying about going out of bounds with my index?
Just one word of advise, using Vector is easy, but not a good idea. Use ArrayList, Vector was introduced in jdk 1.1 maybe? you can see that it doesn't have the standard methods in the new data strcuture class in jdk2.
Originally posted by Adrian Yan: Just one word of advise, using Vector is easy, but not a good idea. Use ArrayList, Vector was introduced in jdk 1.1 maybe? you can see that it doesn't have the standard methods in the new data strcuture class in jdk2.
Vector was introduced in good-old Java 1.0. Since Java 1.2 Vector has extended AbstractList, so it compatable with the rest of the java.util package. The major complaint against Vector is that all its methods are synchronized, which increases the overhead of calling them. I would use the API-provded javax.swing.table.DefaultTableModel unless profiling one's program reveals that using DefaultTableModel is taking an extraordinary amount of time due to synchronization. Then I would look at implementing my own version of javax.swing.table.TableModel using ArrayLists or some sort of paging mechanism.