我创建一个 dataTable 和 cellEditor 形成一列。本专栏是简单的 jSpinner。我有以下问题。当我在微调器中输入一些值并选择另一行时,前一行中的值不会改变。如果我按 ,它会完成。如果我选择或按钮,它也会完成。但是,如果我输入值并更改选择,则不会完成。请帮忙。这是 CellEditor 代码。
public class DurationTableCellEditor extends AbstractCellEditor implements TableCellEditor{
final JSpinner spinner = new JSpinner();
// Initializes the spinner.
public DurationTableCellEditor() {
spinner.setModel(new SpinnerNumberModel(1,1,50000,1));
}
// Prepares the spinner component and returns it.
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
spinner.setValue(new Integer(value.toString()).intValue());
spinner.setCursor(null);
return spinner;
}
// Enables the editor only for double-clicks.
@Override
public boolean isCellEditable(EventObject evt) {
if (evt instanceof MouseEvent) {
return ((MouseEvent)evt).getClickCount() >= 1;
}
return true;
}
// Returns the spinners current value.
public Object getCellEditorValue() {
return spinner.getValue();
}
}