tags:

views:

140

answers:

1

I have populated my jTable with the following Code. It has two columns, the first has variable name and the second is a list of its dependencies. The user can change the dependencies by selecting them from the list in the jTable.

When the user changes a value, I want to row to be added to another jTable (which would be no user editable. How would I do that?

The code to populate the table is

      Vector<Vector> data = new Vector<Vector>();
      for (String v : acn.getVariableNames()) {
        Vector tmp = new Vector();
        tmp.add(v);
        ArrayList<String> temp = new ArrayList<String>();
        for (String u : acn.getVariableDomain(v)) {
            temp.add(u);
        }
        tmp.add(temp);
        data.add(tmp);
    }
    Vector names = new Vector();
    names.add("Variable");
    names.add("Domain Value");
    DefaultTableModel dt = new DefaultTableModel();
    dt.setDataVector(data, names);

    jTable2.setModel(dt);
    jTable2.getColumnModel().getColumn(1).setCellEditor(new ChangeImpactEditor());
    jTable2.getColumnModel().getColumn(1).setCellRenderer(new TableListRenderer());
A: 

The way i would do it is to override

public void setValueAt(Object aValue, int rowIndex, int columnIndex);

from your TableModel. The setValue method get called by the JTable after the user has editted a value

In your overriden method you then can set the value in the other tablemodel

Peter