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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
@Override
public void setValueAt(Object p_Value, int p_iRowIndex, int p_iColumnIndex) {
// ---------------------------------------------------------------------
// Declaration de variables necessaires
//-----------------------------------------------------------------------
Cell cell = null;
// ---------------------------------------------------------------------
// on verifie avant que les valeurs sont des double
// ---------------------------------------------------------------------
if (m_MapValueAt != null) {
m_Table = (JTable) getTableModelListeners()[0];
// ------------------------------------------------------------------
// on recupere la valeur saisie
// ------------------------------------------------------------------
cell = m_MapValueAt.get(p_iColumnIndex);
if (cell != null) {
try {
if (p_Value instanceof Number) {
//------------------------------------------------------------------
// on test la valeur min et max
//------------------------------------------------------------------
checkValue(cell, (Number) p_Value);
//------------------------------------------------------------------
// on formatte la valeur
//------------------------------------------------------------------
if (p_Value instanceof Double) {
super.setValueAt(FormatTools.formatValueDouble((Double) p_Value,
cell.getNbDecimal()), p_iRowIndex, p_iColumnIndex);
}
else {
super.setValueAt(p_Value, p_iRowIndex, p_iColumnIndex);
}
}
}
catch (NumberFormatException e) {
// ----------------------------------------------------------------
// Affichage de l'erreur
// ----------------------------------------------------------------
//super.setValueAt(p_Value, p_iRowIndex, p_iColumnIndex);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
m_Table.editCellAt(p_iRowIndex, p_iColumnIndex);
m_Table.getEditorComponent().requestFocus();
TableCellEditor editor = m_Table.getCellEditor(p_iRowIndex,
p_iColumnIndex);
Component editorComp = m_Table.prepareEditor(editor, p_iRowIndex,
p_iColumnIndex);
if (editorComp instanceof JTextField) {
JTextField field = (JTextField) editorComp;
field.setBorder(BorderFactory.createLineBorder(Color.red));
field.setText(p_Value.toString());
field.selectAll();
}
}
});
}
}
else {
super.setValueAt(p_Value, p_iRowIndex, p_iColumnIndex);
}
}
else {
super.setValueAt(p_Value, p_iRowIndex, p_iColumnIndex);
}
} |
Partager