2010-05-26 138 views
0

如何在从JTextField的显示一个JTable的一排时,一下就行,获得细胞ODF 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 
    } 


    } 

回答

0

使用ListSelectionListener。只要选择了一行,就可以使用table.getValueAt(...)从给定行的模型中获取数据,然后在窗体的文本字段中显示数据。