[JTable] Cellule non modifiable
Salut,
Je n'arrive pas à modifier une cellule lorsque je la sélectionne.
Pourquoi ? :wink:
Définition de la table :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
private JTable getTNomsChamps() {
if (tNomsChamps == null) {
tNomsChamps = new JTable();
tNomsChamps.setShowGrid(true);
tNomsChamps.setEnabled(true);
tNomsChamps.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
tNomsChamps.setModel(tmNomsChamps);
tNomsChamps.setCellSelectionEnabled(true);
tcmNomsChamps = tNomsChamps.getColumnModel();
tcNomsChamps = tcmNomsChamps.getColumn(0);
tcNomsChamps.setPreferredWidth(10);
tcNomsChamps = tcmNomsChamps.getColumn(1);
tcNomsChamps.setPreferredWidth(60);
thNomsChamps = tNomsChamps.getTableHeader();
thNomsChamps.setPreferredSize(new Dimension((int) thNomsChamps.getPreferredSize().getWidth(), 25));
tNomsChamps.setRowHeight(20);
tNomsChamps.setVisible(true);
}
return tNomsChamps;
} |
Définition du modèle de la table :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
public class TMNomsChamps extends AbstractTableModel
{
public int getColumnCount() {
return 2;
}
public int getRowCount() {
return getVStrChamps().size();
}
public String getColumnName(int col) {
return ENTETE_NOMS_CHAMPS[col];
}
public Object getValueAt(int row, int col) {
return String.valueOf(((Vector) getVStrChamps().elementAt(row)).elementAt(col));
}
public Class getColumnClass(int c) {
return String.class.getClass();
}
public boolean isCellEditable(int row, int col) {
return true;
}
public void setValueAt(Object value, int row, int col) {
((Vector) getVStrChamps().elementAt(row)).setElementAt(value,col);
fireTableCellUpdated(row, col);
}
} |
Définition des paramètres de la table :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// table noms champs
private JTable tNomsChamps = null;
private JScrollPane spNomsChamps = null;
public final String[] ENTETE_NOMS_CHAMPS = {
"<html><b>" + "NUM" + "</b></html>",
"<html><b>" + "NOM" + "</b></html>"
};
private TMNomsChamps tmNomsChamps = new TMNomsChamps();
private JTableHeader thNomsChamps = null;
private TableColumn tcNomsChamps = null;
private TableColumnModel tcmNomsChamps = null;
private Vector vStrChamps = null; |
Merci d'avance. :wink: