Com Editor abaixo eu capturo a ação do usuário através da tecla “Enter” implementado através do ActionListiner, mas quando o usuário utiliza o mouse o método getCellEditorValue não é acionado. Alguém tem alguma sugestão de como capturo o evento quando o editor perde o foco.
public class NotaTableEditor extends AbstractCellEditor implements
TableCellEditor {
private JFormattedTextField numero = null;
private static DecimalFormat formatter = new DecimalFormat("#,##0.00");
private JFormattedTextField getCell() {
if ( numero == null) {
numero = new JFormattedTextField(formatter);
numero.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stopCellEditing();
}
});
}
return numero;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
JFormattedTextField cell = getCell();
cell.setText("");
if (value instanceof Nota) {
Nota nota = (Nota) value;
cell.setValue(nota.getValor());
}
return cell;
}
@Override
public Object getCellEditorValue() {
Double valor = (Double) getCell().getValue();
System.out.println(valor);
Nota nota = new Nota();
nota.setValor(valor);
return nota;
}
}