get cells odf a JTable

Posted by tuxou on Stack Overflow See other posts from Stack Overflow or by tuxou
Published on 2010-05-26T18:52:44Z Indexed on 2010/05/26 20:21 UTC
Read the original article Hit count: 436

Filed under:
|
|
|
|

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
   }


  }

© Stack Overflow or respective owner

Related posts about java

Related posts about database