Project Idea: Cleaner ways of hooking up a list of beans to a JTable.
Please forgive the long winded post, I'm just thinking out-loud here. I
wouldn't be surprised if there is already a project that supports this,
but it would be nice if there was a small, self-contained library that
handled this (and other similar Swing "*Model" class use-cases).
It is often the case that want to present a table which is backed by a
list of beans, where there is a set of properties which correspond to
the columns of the table.
Swing provides a somewhat round-about way to handle this. If you use a
default TreeModel (or if you create your own), you have to wire up a lot
of code that handles row insertion/deletion, as well as property value
The project I propose: Using some sort of IoC (probably AOP, or some
sort of Proxy, but the less biolerplate code, the better) add the
appropriate PropertyChangeListener support to a class of beans, and
create a TableModel which will handle the appropriate connections of
property listeners to table events.
When requesting a TableModel, you can specify the Bean class and a
mapping of property names to column names. You should be able to omit
properties you don't want to show up ("class" would be a common
example). Also, a simple way to bind cell renderers/editors to a
property would be useful.
It might also be useful to provide a way that beans can provide default
values for column names/editors/renderers through Annotations. That
way, if the bean is reused in several different table, there is a
Oh, and anywhere that it is feasible, Generics should be used for
type-safety. As an analogue, it is possible to create a class
GenericListModel<T> implements ListModel, java.util.List<T>, for
typesafe access to the contents of the model.
Is anyone interested in collaborating on such a project? Are there
existing projects which fulfill this need, even if only partially?
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>