aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Dynamic Tables? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dynamic Tables?" Watch "Dynamic Tables?" New topic
Author

Dynamic Tables?

Jacob Steingart
Ranch Hand

Joined: Mar 28, 2008
Posts: 63
Hey everyone,
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.

-GUI Newbie


I never know what to put in my signature...
Suraj Chandran
Ranch Hand

Joined: May 20, 2008
Posts: 53
Every time you add/remove/change books in your table, you just need to call one of the fireXXX methods in the AbstractTableModel.


I guess there are couple of design issues in this classic software the GOD coded.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

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
2) getColumnName()
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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Dynamic Tables?