Customizing Alarm status table

I recently developed a way to accomplish this. Here is the code:

def columnLabeler(alarmStatusTable):
	if alarmStatusTable.componentCount > 0:
		for table in alarmStatusTable.getComponents():
			if 'AlarmStatusTable$1' in str(table.__class__):
				tableHeaders= table.getTableHeader()
				columnModel = table.getColumnModel()
				for column in range(table.columnCount):
					tableColumn = columnModel.getColumn(column)
					tableColumn.setHeaderValue("Custom Column Name " + str(column + 1))
				tableHeaders.repaint()
			columnLabeler(table)
alarmStatusTable = event.source.parent.getComponent('Alarm Status Table')
columnLabeler(alarmStatusTable)

The code finds the table within the component, and then loops through the columns using normal jtable methods to apply custom headers. This version is written for the actionPerformed event handler of a button in the same container as the Alarm Status Table.

The preceding code produces the following result:
image

One thing that is interesting about the code is that even if the client hides and reshows the column, the table remembers the replacement name. That said, the code will have to be ran from either an onInternalFrameOpened event script or something that works in this way, because if the window is closed, the table will not remember the next time the window is opened.

2 Likes