This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm writing some software to (attempt) to help me organize/catalog my home library, and I'm trying to make it so I can dynamically add books to a big JTable of them and info about them. What I want to do is have an ArrayList (or other dynamic array-esque thing) that contains a bunch of Book objects. Each Book will have instance variables such as a title, author, ISBN, etc. How can I make a table/table model that will display this data.
Table model from ArrayList! My favorite design approach!
In your custom table model (just extend default table model if you are new to tables), you need to override the following methods
1) getColumnCount() Ideally these will be the fields in your Book object, which you want to display on the table
3) getRowCount() Ideally this will return the size of your ArrayList. Typical pitfall area for a NPE! You have been warned!
4) getValueAt() This returns the values for the individual cells.
5) getColumnClass() Override this if you are interested in special renderers. By default, it returns Object.class