我正在尝试将组合框作为编辑器添加到jython中的表列中。由于我想根据我试图实现AbstractCellEditor
来设置自定义编辑器的行来选择值selectabel,我的代码大致是:
from javax.swing.table import TableCellEditor
from javax.swing import AbstractCellEditor
class customCombo(TableCellEditor):
def __init__(self):
self._box = JComboBox( editable = False );
#button.setActionCommand(EDIT);
#self._box.actionListener = self.actionPerformed
def actionPerformed(self, event):
print "well we should do something"
def getCellEditorValue(self):
return self._box.selectedItem
def getTableCellEditorComponent(self, table, value, isSelected, row, col):
#TODO: customize the dropdown
self._box.removeAll()
self._box.add("head") #should this be addItem
return self._box
class table(object):
def __init__(self):
...
self._table.columnModel.getColumn(8).cellEditor = customCombo()
由于我刚接触摇摆,我试图从http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editor翻译示例。然而,它只是“有效”(如在运行中,但不按预期行事,我永远不会看到组合框),如果我实现TableCellEditor
,但根据示例:
AbstractCellEditor类是一个很好用的超类。它实现了TableCellEditor的超级接口CellEditor,为您节省了实现单元编辑器所需的事件触发代码的麻烦。
因此,我想实现AbstractCellEditor
,但这样做会产生:
TypeError:无法转换 org.python.proxies.cross.gui.ipTable$customCombo$2@3da850 to javax.swing.table.TableCellEditor
作为一个愚蠢的问题:
如何使self._box.actionListener = self.actionPerformed
行有效?
我找到了Event handling with Jython & Swing,但是我不知道如何将其转移到我的案例中,特别是因为我不想将父(table)绑定到customCombo
答案 0 :(得分:1)
多重继承是关键:
class customCombo(TableCellEditor, AbstractCellEditor):