Force configure cell update in power table

The much more efficient solution is to embed a custom editor, which will lookup the datasets dynamically whenever it’s appropriate. I’ve got a very simple example of this below; the project has an editable ‘Options’ dataset, and the available options in column B in the editable table will be dynamic based on the value in column A.

The relevant code is here:

		root = self
		from javax.swing import JComboBox, DefaultCellEditor, DefaultComboBoxModel
		
		class CustomCellEditor(DefaultCellEditor):
			def getTableCellEditorComponent(self, table, value, isSelected, row, column):
				comp = DefaultCellEditor.getTableCellEditorComponent(self, table, value, isSelected, row, column)
				data = []
				target = root.parent.getComponent("Options")
				for r in range(target.data.rowCount):
					if target.data.getValueAt(r, 0) == root.data.getValueAt(row, 0):
						data = target.data.getValueAt(r, 1).split(",")
				comp.setModel(DefaultComboBoxModel(data))
				return comp
		return {'editor': CustomCellEditor(JComboBox())}

Specifically, comp.setModel(DefaultComboBoxModel(data)) - every time the table asks the editor what renderer it should use, the CustomCellEditor will fire getTableCellEditorComponent and refresh the data in the dropdown.

Custom Editor.proj (9.2 KB)

11 Likes