Today, I developed a dark mode for the alarm status table, and indeed, the header was a bit tricky. The top right corner can be set directly, but to change the header itself, I ended up setting it's background to transparent, so the underlying color could come through. The top left corner underneath the multistate button is a buffered image, so I ended up having to create a graphic to paint over it.
Here is the result:
Here is the full code for dark mode in a version that was set up on the actionPerformed event handler of a test button located in the same container as the table:
Original Source Code
from java.awt import Color
#Sets Footer Color
event.source.parent.getComponent('Alarm Status Table').getComponent(0).background = Color(57,56,61)
#Colors the divider at the right side of the footer
event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(1).getComponent(1).background = Color(57,56,61)
#Acknowledge Button Color
event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(1).getComponent(0).getComponent(0).background = Color(57,56,61)
#Shelve Button Color
event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(1).getComponent(0).getComponent(1).background = Color(57,56,61)
#Colors the gridlines and any uncovered background for the table
event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(0).getComponent(1).getComponent(0).getComponent(0).getComponent(0).background = Color(57,56,61)
# Allows header to inherit the background color of the underlying panel
event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(0).getComponent(1).getComponent(0).getComponent(0).getComponent(0).getTableHeader().setOpaque(False)
#Sets the font color of the header row
event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(0).getComponent(1).getComponent(0).getComponent(0).getComponent(0).getTableHeader().setForeground(Color(248,248,248))
#Sets the background color for the header
event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(0).getComponent(1).getComponent(0).getComponent(5).getComponent(0).background = Color(57,56,61)
#Colors the alarm selection buttons
event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(0).getComponent(1).getComponent(0).getComponent(3).getComponent(0).background = Color(57,56,61)
#Colors the multiselect button itself in the top left corner
event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(0).getComponent(1).getComponent(0).getComponent(4).getComponent(0).background = Color(57,56,61)
#Colors the top right corner
event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(0).getComponent(1).getComponent(0).background = Color(57,56,61)
#Paints the corner behind the multiselect box in the top left of the table
corner = event.source.parent.getComponent('Alarm Status Table').getComponent(0).getComponent(0).getComponent(1).getComponent(0).getComponent(4)
corner_Field = corner.getClass().getDeclaredField('corner')
corner_Field.setAccessible(True)
corner_Value = corner_Field.get(corner)
graphics = corner_Value.createGraphics()
graphics.setPaint(Color(57,56,61))
graphics.fillRect (0, 0, corner_Value.getWidth(), corner_Value.getHeight())
Edit: Encountered a scenario where the original source code didn't work due to a variation in the way the table was structured that resulted in a "No Child 5" error
Here is a generic version that should work no matter how the table is structured:
Revised Source Code
def setDarkMode(alarmStatusTable):
from java.awt import Color
if alarmStatusTable.componentCount > 0:
for component in alarmStatusTable.getComponents():
try:
component.foreground = Color(248,248,248)
except:
pass
try:
component.background = Color(57,56,61)
except:
pass
try:
component.getTableHeader().setOpaque(False)
component.getTableHeader().setForeground(Color(248,248,248))
except:
pass
try:
corner = component
corner_Field = corner.getClass().getDeclaredField('corner')
corner_Field.setAccessible(True)
corner_Value = corner_Field.get(corner)
graphics = corner_Value.createGraphics()
graphics.setPaint(Color(57,56,61))
graphics.fillRect (0, 0, corner_Value.getWidth(), corner_Value.getHeight())
except:
pass
setDarkMode(component)
alarmStatusTable = event.source.parent.getComponent('Alarm Status Table')
setDarkMode(alarmStatusTable)