We get that behavior by overriding JTable prepareRenderer which then fires a
(custom) method called fireCellFocus. The fireCellFocus method calls
requestFocus() on a cell's editor.
public Component prepareRenderer(TableCellRenderer renderer,
int row,
int column) {
boolean rowIsAnchor = (getSelectionModel().getAnchorSelectionIndex
() == row);
boolean colIsAnchor =
(columnModel.getSelectionModel().getAnchorSelectionIndex
() == column);
boolean hasFocus = (rowIsAnchor && colIsAnchor) && hasFocus();
if (hasFocus) {
// System.out.println("Cell has focus " + row + "/" + column);
fireCellFocus(row, column);
}
return super.prepareRenderer(renderer, row, column);
}
// leaving out some of the implementation details:
protected void fireCellFocus(int row, int column) {
// no op if the current cell editor has a
// validation exception
if (isEditing()) {
TableCellEditor editor = getCellEditor();
if (editor != null) {
if (!editor.shouldSelectCell(new EventObject(this))) {
return; // there is a validation error
}
}
}
// otherwise, put the new cell into edit mode
if (row != _lastFocusRow || column != _lastFocusCol) {
// ...
// Our subclass of table model asks whether a table
// cell should automatically go into edit mode when
// the user tabs into it.
if (dataModel.shouldAutoEditCell(row,
convertColumnIndexToModel(column))) {
if (this.isEnabled()) {
if (editCellAt(row, column)) {
TableCellEditor editor = getCellEditor(row, column);
if (editor instanceof MyCustomTableCellEditor)
((MyCustomTableCellEditor)editor).requestFocus();
}
}
}
_lastFocusRow = row;
_lastFocusCol = column;
}
}
-----Original Message-----
From: Andy Wiese
To: advanced-swing
Sent: 1/12/02 10:53 PM
Subject: JTable Cell Editiing
How can I cause editing to commence immediately when the navigates to a
cell with the keyboard?
Andy Wiese
--code carpenter amongst software engineers--
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing