2010-05-26 3 views
0
행에 클릭이

세포를 얻을 ODF JTable로

(I이이 JTable의에서 데이터베이스를 편집해야) 할 때의 JTextField의에서에

내 테이블을 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 (...)를 사용하여 주어진 행에 대한 모델의 데이터를 가져온 다음 폼의 텍스트 필드에 데이터를 표시합니다.

관련 문제