Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JTable using Vector vs ArrayList

843806Jun 24 2009 — edited Jun 26 2009
I have a mostly working sollution thus far and was getting to the point where I was going to put my actual data (been working with dummy hand-jammed data up until now) into my JTable. The GUI is designed and all is working great thanks to a lot of help from people here.

So now the dilema: I currently have my reader dumping my data into an ArrayList<Course>. My course class is rather simple
public class Course
{
  private String ID;
  private String CourseName;
  private String City;
  private String State;
  private String Zip;
  private int CoursePar;
  private double Rating;
  private int Slope;
  private String TeePosition;
  private int Yardage;
  private int[] HolePar;
  private int NumRounds;
.....
After extensive reading and searching, I've figured out that 1. you can't use an ArrayList with a JTable unless you override the default table model and 2. I don't know enough to try to override the model. So I kept reading and searching.

What I found is that since JTable has a contructor that takes vectors, that maybe the vector was the way to go. Before I go tearing apart my working code to try to hack vectors in place of my array lists though, is that the best way - and yes I realize "best" is not completely objective.

So if instead of
public static ArrayList<Course> CSX=new ArrayList<Course>();
I use
public static Vector<Course> CSX=new Vector<Course>();
will it still work AND will I then be able to use that vector in the JTable
DefaultTableModel dtm=new DefaultTableModel(CSX, tbl_CourseList_Heading);
I realize I'll probably have to change the heading from a String[] to a Vector as well but I'm sure that's easy.

As always, thanks for the time and input!!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 24 2009
Added on Jun 24 2009
14 comments
1,314 views