tags:

views:

44

answers:

2

In my Swing app, I have a POJO class called Command. Command has a few subclasses. Most of the Command subclasses consist of 2 or 3 Strings. But the data in one of the Command subclasses has a fairly different data format.

I also have a class called CommandEditor, which creates the GUI for viewing and editing the various Command subclasses. CommandEditor creates a JPanel that contains a horizontal Box. For the Command subclasses that contain 2 or 3 Strings, the Box contains 2 or 3 corresponding JTextFields. And for the odd subclass, the Box contains the appropriate widgets for viewing and editing that subclass's data.

I am able to put together a form that contains a bunch of CommandEditors, and it all works nicely.

But now I need to deal with an ArrayList of Commands. All of the Commands in the ArrayList are guaranteed to be of the same subclass, which means that the corresponding CommandEditors for each of the Commands will look basically the same (having a similar shape)

What the customer wants is something that looks like a table of CommandEditors.

What's the best way to do this? Can I pass a Vector of CommandEditor objects into a JList (such that the JList puts the CommandEditors into rows, and the CommandEditors provide the illusion of having columns)? Or is there a better way?

+1  A: 

One approach would be to use a JTable and implement the TableCellEditor interface, as suggested in this example. You could create a different PopupDialog for each kind of CommandEditor. See How to Use Tables for additional examples.

trashgod
+1  A: 

It seems like you only need one column of CommandEditors, so JList would've been easier to use had it support cell editor like JTable does.

If you have the luxury to venture beyond swing, Apache Pivot's list supports cell editor. I haven't personally used it but I've seen good reviews.

Geoffrey Zheng