• Post Reply Bookmark Topic Watch Topic
  • New Topic

Single ArrayList populating two different Tables

 
James Dudley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an issue with JTables and ArrayList and is getting over complicated for me to work out the best way to do this

I am loading a new JPanel from a class that displays two JTables. 1 with 8 rows and another with 4 rows. These are displayed correcrtly

I am passing an Arraylist into this class. This contains a number of objects.
1 of the values within the object defines which table the rest of the objects values should populate

Trouble I am having is I worked out how to populate the first table but then crashes when the number of rows is larger then the first tables rows

Here is some of the code
The Object that is being passed within an ArrayList. Distance is the reference to the table.



creating the tables


ArrayList I am passing in is called ScoreEndArrayList

Anymore info needed please ask

Thanks


 
James Dudley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
moved thinks around with no luck. I made it so both tables are created but then stopped at getting the arraylist into them

Am I over complicating it or do I need to do something with the arraylist first. ie break it up
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
 
James Dudley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, think I was just over complicating it to get my point

Basically as stated above I have an ArrayList with a number of objects in it.
Each object has a reference number which relates to the table I want that specfic object to be populated into

Number of tables will change depending on the different reference numbers. 1 to 4 will be the normal

 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your post is confusing. You said you are passing an ArrayList, but the code:

shows that you are only passing an Object to the model.

And you are creating the table inside the loop, but populating it outside the loop. It will crash with 'ArrayOutOfBoundsException'
 
James Dudley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
worked it out

Created the tables separate but did not set the model until I passed the data to it. then I could with IF statements pull out the data needed
Trouble I had was it was crashing due to OutofBoundsIndex exception and then realised that I could catch that and do nothing with it and the code progressed on happily

Basically I forgot you can throw exceptions and do something with them when the code will always throw exceptions
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!