thanks for your insight on the protocol. I'm looking into it now.
I created a table cell editor that extends JComboBox and implements
TableCellEditor. It's constructor installs my custom key selection
manager (I followed the JScrollBar sample from Chapter 15 of Eckstein,
Loy, and Wood) . I got what I wanted, but I don't know why. my
fireEditingStopped implementation is similar to
AbstractTableCellEditor's implementation. I guess I don't understand
the protocol these components use, but I am satisfied with how things
are going. Are you aware of any ramifications I should know about?
public class AshtonComboBoxTableCellEditor extends JComboBox
implements TableCellEditor {
protected transient Vector listeners;
protected transient Object origValue;
public AshtonComboBoxTableCellEditor(Vector parts) {
setKeySelectionManager(new AshtonComboBoxKeySM());
listeners = new Vector();
for (int i=0, n=parts.size(); i<n; i++)
addItem(parts.get(i));
}
public Component getTableCellEditorComponent(JTable table, Object
value,
boolean isSelected,
int row, int column)
{
if (value == null)
return this;
setSelectedItem(value);
table.setRowSelectionInterval(row, row);
table.setColumnSelectionInterval(column, column);
origValue = getSelectedItem();
return this;
}
public Object getCellEditorValue() {
return getSelectedItem();
}
public boolean isCellEditable(EventObject anEvent) {
return true;
}
public boolean shouldSelectCell(EventObject anEvent) {
return true;
}
public boolean stopCellEditing() {
fireEditingStopped();
return true;
}
public void cancelCellEditing() {
fireEditingCancelled();
}
public void addCellEditorListener(CellEditorListener l) {
listeners.addElement(l);
}
public void removeCellEditorListener(CellEditorListener l) {
listeners.removeElement(l);
}
protected void fireEditingCancelled() {
setSelectedItem(origValue);
ChangeEvent ce = new ChangeEvent(this);
for (int i=listeners.size()-1; i>=0; i--)
((CellEditorListener)listeners.elementAt(i)).editingCanceled(ce);
}
protected void fireEditingStopped() {
ChangeEvent ce = new ChangeEvent(this);
for (int i=listeners.size()-1; i>=0; i--)
((CellEditorListener)listeners.elementAt(i)).editingStopped(ce);
}
Kleopatra - 27 Nov 2003 15:06 GMT
> I created a table cell editor that extends JComboBox and implements
> TableCellEditor. It's constructor installs my custom key selection
[quoted text clipped - 4 lines]
> the protocol these components use, but I am satisfied with how things
> are going. Are you aware of any ramifications I should know about?
the main difference is that your custom cellEditor is not terminating
edits without explicite requests from some client code - the default is
listening to actionEvents fired by the combo - which may be okay in your
case. Don't know for sure.
Something unrelated: your code can alter the state of the table during
editing
> public Component getTableCellEditorComponent(JTable table, Object
> value,
[quoted text clipped - 7 lines]
> table.setRowSelectionInterval(row, row);
> table.setColumnSelectionInterval(column, column);
^^^^^^^^
NEVER do such a thing ... you can get very nasty effects by doing so.
Greetings
Jeanette