Customizing Power Table Headers and Backgrounds

I have a Power Table that I would like to change the color of the background and foreground(font) of the header row. Also, the table does not always fill the entire area if there are few records returned and while the background is a property you can change in the prop editor the area left over by the table is still white. I cannot find anything in the documentation about finding or identifying the specific properties I need to call or modify. I’ve attached an image of what I need to change. Also, below is the code I tried in a couple different variations however I get an error that the component does not have an attribute ‘TableHeader’ or whatever I’ve tried from various posts on the forum. Where do I find available properties/attributes that I can manipulate for each component (more than what appears in the dropdowns or the properties editor) such as header background or foreground? Also, an example if my code is in error would be greatly appreciated. Thanks in advance for your help and support!

[code]#First Attempt on the table component script
from java.awt import Color
event.source.background = Color(0,0,0)
event.source.getTableHeader().setBackground(Color(0,0,0))

#Second Attempt on the Root Container script
from java.awt import Color

bg=Color(0,0,0)
tbl = event.source.getComponent(‘ProductionLogTable’)

tbl.getTableHeader().setBackground(bg)[/code]


Hmm, interesting problem. Sent me off into a research spin. The following works for me in a script playground:

tbl.table.tableHeader.background = system.gui.color("cyan") tbl.viewport.background = system.gui.color("black")

Thanks Phil, all but the header background changed. I was able to change the font with the foreground property but the background will not change. Hmmmm. I’m wondering if there could be something built into the component that overrides scripting for the header background? Here’s what worked on all but the header background:

event.source.table.tableHeader.background = system.gui.color("black")
event.source.table.tableHeader.foreground = system.gui.color("cyan")
event.source.viewport.background = system.gui.color("black")

Thanks for the help Phil! Much appreciated! :smiley:

I was testing on 7.7.4 where it all works. What version are you using?

I’m currently using 7.7.0. I will upgrade this weekend and see if that remedies the issue. Thanks for pointing that out.

Necromancing but to complete the answer for anyone else looking, the above solution changes the background of the table header and viewport, but not the background of the table header’s cells, so you end up with this:

Screenshot_1

To change the background of the actual header cells (and the border), I used the configureHeaderStyle Extension Function (I felt this was a cleaner solution as it gets called automagically when the table is rendered)

	from javax.swing import BorderFactory
	from java.awt import Color
	border = BorderFactory.createLineBorder(Color(238,236,232))

	return {
		'background': 'c8c8c8'
		, 'border': border
	}

and in the initialize Extension Function, I did

	from java.awt import Color
	self.viewport.background = Color(200,200,200)

to update the viewport background. The only change from @pturmel’s code here is the reference to the table component gets changed to self

Then the table looks like

Screenshot_3

I realize things could have changed since 7.7.4, but this thread still pops up when you search for changing header colors on power tables so I figured I’d document the direction I went with this

Cheers

8 Likes