views:

499

answers:

1

I am using a bound JTable to display a list of entities.


    // selSteps is a List of entities.
    selStepsBound = ObservableCollections.observableList(selSteps);

    JTableBinding jTableBinding = SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, selStepsBound, tblSelSteps, "tblSelStepsBinding");
    ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${steporder}"));
    columnBinding.setColumnName("Order");
    columnBinding.setColumnClass(Integer.class);
    columnBinding.setEditable(false);
    columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${name}"));
    columnBinding.setColumnName("Description");
    columnBinding.setColumnClass(String.class);
    bindingGroup.addBinding(jTableBinding);
    jTableBinding.bind();

    bindingGroup.bind();

This works fine for displaying the original data. I can even remove items from the bound observableList and I automatically get the JTable UI updated.

The problem is when I change the property value of an entity, that value is not reflected in the JTable UI.

How do I notify the JTable about the changes?

A: 

I'm not super familiar with the SwingBindings stuff, but it appears that while your List is Observable (i.e. listeners will be notified of changes) your entity is not. So nobody is listening to the changes of your entity.

The way I'd typically notify JTable of a change in one of its entities would be to fire a TableModelEvent from the table's model. This is what the JTable is listening for to update itself. I typically extend from ABstractTableModel so that I can call nice functions like fireTableCellUpdated(row,col), etc. How this strategy can be blended with the SwingBindings stuff, I'm not quite sure though...

CarlG