0

单击行时如何在 JTextField 的 from 中显示一行 jtable,

(我需要这个来编辑 JTable 中的数据库)

我的桌子模型

 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
   }


  }
4

1 回答 1

0

使用 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.

于 2010-05-26T20:19:33.577 回答