This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General 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:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

AbstractTableModel advice

 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • 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?
 
Ranch Hand
Posts: 704
  • 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 VI Editor Tomcat Server
  • 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!