views:

20

answers:

1

hi

how to display a row of a jtable in a from of JTextField when click on the row,

( I need this to edit the data base from the JTable )

My table model

 static class TableDataModel extends AbstractTableModel
{
private List nomColonnes;
private List tableau;

public TableDataModel(List nomColonnes, List tableau){
   this.nomColonnes = nomColonnes;
   majDonnees(tableau);
}
public void majDonnees(List nouvellesDonnees){
  this.tableau = nouvellesDonnees;

  fireTableDataChanged();
}

public int getRowCount(){
   return tableau.size();
}

public int getColumnCount(){
    return nomColonnes.size();
  }


  public Object getValueAt(int row, int col){
   return ((ArrayList)( tableau.get(row))).get(col);
 }

 public String getColumnName(int col){
   return nomColonnes.get(col).toString();
 }

 public Class getColumnClass(int c)
 {
   return getValueAt(0,c).getClass();
 }

 public boolean isCellEditable(int row, int col){
  return true;

 }

 public void setValueAt(Object value, int row, int col)
 {
 ((List)tableau.get(row)).set(col,value);
 fireTableCellUpdated(row, col);


  //i suppose i should update the database here
   }


  }
A: 

Use a ListSelectionListener. Whenever a row is selected you get the data from the model for the given row using table.getValueAt(...) and then you display the data in the text field of your form.

camickr