Table headers not centered

You’ll probably want this to fire automatically - probably on propertyChange of the data attribute, but this should get you started. table.getColumnModel().getColumn(1) sets the index of the column to modify (from 0, counting from left to right).

from javax.swing.table import TableCellRenderer

table = event.source.parent.getComponent('Table').getTable()

class NonSortableHeaderRenderer(TableCellRenderer):
	def getTableCellRendererComponent(self, table, value, selected, focused, row, col):
		renderer = table.getTableHeader().getDefaultRenderer()
		comp = renderer.getTableCellRendererComponent(table, value, selected, focused, row, col)
		comp.setIcon(None)
		return comp
		
table.getColumnModel().getColumn(1).setHeaderRenderer(NonSortableHeaderRenderer())

2 Likes