01: package com.salmonllc.swing.table;
02:
03: import java.awt.Component;
04: import java.util.EventObject;
05:
06: import javax.swing.DefaultCellEditor;
07: import javax.swing.JTable;
08: import javax.swing.text.JTextComponent;
09:
10: import com.salmonllc.swing.SComboBox;
11: import com.salmonllc.swing.SComponentHelper;
12:
13: public class ComboBoxCellEditor extends DefaultCellEditor {
14: SComboBox _cbx;
15:
16: public ComboBoxCellEditor(SComboBox comboBox) {
17: super (comboBox);
18: _cbx = comboBox;
19: }
20:
21: /**
22: * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(JTable, Object, boolean, int, int)
23: */
24: public Component getTableCellEditorComponent(JTable table,
25: Object value, boolean isSelected, int row, int column) {
26: SComboBox box = (SComboBox) super .getTableCellEditorComponent(
27: table, value, isSelected, row, column);
28: box.setSelectedItem(value);
29: if (box.isEditable()) {
30: String val = (value == null ? null : value.toString());
31: if (!SComponentHelper.valuesEqual(box.getValue(), val))
32: ((JTextComponent) box.getEditor().getEditorComponent())
33: .setText(val);
34: } else
35: box.setSelectedItem(value);
36: return box;
37: }
38:
39: public boolean isCellEditable(EventObject anEvent) {
40: return true;
41: }
42: }
|