I am trying to add a combobox as editor to a table column in jython. Since I want to have values selectabel depending on the row I am trying to implement AbstractCellEditor
to set a custom editor, my code is approximately:
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()
Since I am new to swing I tried to translate the example from http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editor. However it only 'works' (as in runs but does not behave as desired, I never get to see the combobox), if I implement TableCellEditor
, but according to the example:
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.
Thus I would like to implement the AbstractCellEditor
, however doing so yields:
TypeError: can't convert org.python.proxies.cross.gui.ipTable$customCombo$2@3da850 to javax.swing.table.TableCellEditor
As a bonous question:
How do I make the line self._box.actionListener = self.actionPerformed
work?
I found Event handling with Jython & Swing, however I am not sure how to transfer this to my case, especially since I don't want to bind the parent (table) to customCombo