File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Model for JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Model for JTable" Watch "Model for JTable" New topic
Author

Model for JTable

Terrence White
Ranch Hand

Joined: Jun 26, 2002
Posts: 39
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?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8867
    
    8

javax.swing.table.DefaultTableModel takes either a multidimensional array or a Vector (of Vectors, each being a row) of data among other things.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
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.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8867
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Model for JTable