Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

JTable(Vector param1, Vector param2)  RSS feed

 
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
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.
cheers
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!