This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

AbstractTableModel advice

 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The abstractTableModel seems to want me to have a multidimensional array as the object that holds the data for my JTable.
Specifically, the methods getValueAt(int row, int col) and setValueAt(int row, int col) force me to think in terms of an array.
what if I have an ArrayList full of "Fish" objects?
first solution is to map column numbers to the names of the fields in my object, but that is insane.
second solution is that I can make each column of a certain type (example: Species,weight,length,FishID,stomachContents) and use the column type to look up the value of the field for the object at this row.
what is the best practice for this?
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The names of your columns should be descriptive of what it is your table models. The 2d array is an object which is just used to hold the dataset for your table.
HTH
Nigel
[ April 15, 2004: Message edited by: Nigel Browne ]
[ April 15, 2004: Message edited by: Nigel Browne ]
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nigel,
So, you are saying that I could write out the contents of each "Fish" object to an array and use that array to communicate with the table.
and I can keep an ArrayList of "Fish" arrays which I can then access with the (x,y) coordinates that the position on the table returns. I will try this out
As long as I keep the column names coordinated with the order of fields from the object, I should be OK. If I decide I need to change the order of column names, I would need to go back to my Fish array and change the order of fields in that array.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!