tags:

views:

31

answers:

1

I have created a JDialog which displays two different tables. When the user selects a row from the first table, the content of the second table should update accordingly and display some new data. Can someone give me some guidelines in order to create such table behaviour? Thanks!

+2  A: 
  • make the table model of the second table implement ListSelectionListener and add it as a listener to the first table's selection model
  • make sure you fire fireTableDataChanged() (assuming your table model of the second table extends AbstractTableModel) when valueChanged(..) of the second table's table model is called.

Or you could add an anonymous class doing the forwarding of the corresponding event. Something like:

table1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
  public void valueChanged(ListSelectionEvent e) 
  {
     ... // fill data into table2
     tableModel2.fireTableDataChanged(); // update the display
  }
});    
Andre Holzner