File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTable(Vector param1, Vector param2) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable(Vector param1, Vector param2)" Watch "JTable(Vector param1, Vector param2)" New topic

JTable(Vector param1, Vector param2)

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Recently I have learned that an ArrayList is acually better than a Vector because it is faster. Does anyone know why Sun would not have included a method in there JTable to accept ArrayLists as parameters?

GenRocket - Experts at Building Test Data
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
good question
maybe because of backward compatibality.....
anyway it is very annoying to use the Vectors when constructing a JTable and i agree with you.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
Vector is synchronized while ArrayList is initially not. If they would accept an ArrayList as argument they would have to make sure that it's synchronized. Not, that this is a big problem.
I think they just didn't change the implementation of DefaultTableModel which uses Vector though they are propagating the use of ArrayList to everyone else.
Anyway, as Vector is a subtype of collection it's not that difficult to use ArrayLists and initialize a JTable using a vector, nonetheless:
ArrayList data = new ArrayList();
JTable table = new JTable(new Vector(data));
Another possibility is to create your own TableModel which uses a synchronized ArrayList or HashMap or whatever is the most efficient container in this case.
I agree. Here's the link:
subject: JTable(Vector param1, Vector param2)
jQuery in Action, 3rd edition