Dynamic drop down values in table

Create a power table with test data and paste the following into the configureEditor extension function.
Make the String Column editable.

[code] from javax.swing import AbstractCellEditor,JComboBox
from javax.swing.table import TableCellEditor

class myTableCellEditor(TableCellEditor,AbstractCellEditor):	

	def __init__(self, tableComponent):
		self.table= tableComponent
		self.cbValues = None
	
	def getTableCellEditorComponent(self, table, value, isSelected, rowIndex, vColIndex):	
		# Contents of dropdown will be dependant on this value.
		intColumnValue = self.table.data.getValueAt(rowIndex,"Int Column")
	
		# You can change this to query a database table or hardcode values 
		newList = [intColumnValue + i for i in range(0,10)]

		# Build the Combo box with the values from above
		self.cbValues = JComboBox(newList)

		return self.cbValues
	
	def getCellEditorValue(self):
		return self.cbValues.getSelectedItem()

if colName == "String Column":
	m = myTableCellEditor(self)
	return {"editor":m}[/code]
5 Likes