我试图将一个组合框作为编辑器添加到jython中的表列中。因为我想让值selectabel取决于我试图实现的AbstractCellEditor
来设置自定义编辑器的行,所以我的代码大约是:
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()
因为我是swing新手,所以我尝试将示例从http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editor翻译过来。但是,如果我实现TableCellEditor
,那么它只会“起作用”(就像在runs中那样,但是没有按预期的方式运行,我永远看不到组合框),但是根据这个示例:
The AbstractCellEditor class is a good superclass to use. It implements TableCellEditor's superinterface, CellEditor, saving you the trouble of implementing the event firing code necessary for cell editors.
因此,我希望实现AbstractCellEditor
,但是这样做会产生:
TypeError: can't convert org.python.proxies.cross.gui.ipTable$customCombo$2@3da850 to javax.swing.table.TableCellEditor
作为一个骨瘦如柴的问题:
如何使这条线self._box.actionListener = self.actionPerformed
工作?
我找到了Event handling with Jython & Swing,但是我不确定如何将其转移到我的案例中,特别是因为我不想将父(表)绑定到customCombo
多重继承是关键:
相关问题 更多 >
编程相关推荐