Power table changing border line color

I would like to ask how can change the color or the border line in a power table. Thank you!
Screenshot 2023-03-03 083835

Here is a tutorial I made previously in the forum that explains how to do this:

I just need the borderline not all the columns and rows

Just the one on the left, or the whole outline?

the whole outline

Okay, I've adapted the example code to just do a single border:

#def configureCell([...]):
	from javax.swing import BorderFactory
	from java.awt import Color
	borderColor = Color(0, 0, 0)
	if rowIndex == 0 and colIndex == 0:
		border = BorderFactory.createMatteBorder(2, 2, 0, 0, borderColor)
	elif rowIndex == (self.data.rowCount-1) and colIndex == 0:
		border = BorderFactory.createMatteBorder(0, 2, 2, 0, borderColor)
	elif rowIndex == 0 and colIndex == (self.data.columnCount-1):
		border = BorderFactory.createMatteBorder(2, 0, 0, 2, borderColor)
	elif rowIndex == (self.data.rowCount-1) and colIndex == (self.data.columnCount-1):
		border = BorderFactory.createMatteBorder(0, 0, 2, 2, borderColor)	
	elif rowIndex == (self.data.rowCount-1) and colIndex == 0:
		border = BorderFactory.createMatteBorder(0, 2, 2, 0, borderColor)
	elif rowIndex == 0:
		border = BorderFactory.createMatteBorder(2, 0, 0, 0, borderColor)
	elif rowIndex == (self.data.rowCount-1):
		border = BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor)
	elif colIndex == 0:
		border = BorderFactory.createMatteBorder(0, 2, 0, 0, borderColor)
	elif colIndex == (self.data.columnCount-1):
		border = BorderFactory.createMatteBorder(0, 0, 0, 2, borderColor)
	else:
		border = BorderFactory.createMatteBorder(0, 0, 0, 0, borderColor)
	return  {'border': border}

Result:
image

Note:
for each cell: BorderFactory.createMatteBorder(TOP, LEFT, BOTTOM, RIGHT, borderColor)

Edit: Removed an 8 typo from one of the borders

For an outline that goes around the outside of the header instead of the inside, use the configureHeaderStyle extension function in conjunction with the configureCell to produce the effect:

Example:
configureHeaderStyle Script:

#def configureHeaderStyle(self, colIndex, colName):
	from javax.swing import BorderFactory
	from java.awt import Color
	borderColor = Color(0, 0, 0)
	if colIndex == 0:
		border = BorderFactory.createMatteBorder(2, 2, 0, 0, borderColor)
	elif colIndex == (self.data.columnCount-1):
		border = BorderFactory.createMatteBorder(2, 0, 0, 2, borderColor)
	else:
		border = BorderFactory.createMatteBorder(2, 0, 0, 0, borderColor)
	return  {'border': border}
configureCell Script:
#def configureCell([...]):
	from javax.swing import BorderFactory
	from java.awt import Color
	borderColor = Color(0, 0, 0)
	if rowIndex == 0 and colIndex == 0:
		border = BorderFactory.createMatteBorder(0, 2, 0, 0, borderColor)
	elif rowIndex == (self.data.rowCount-1) and colIndex == 0:
		border = BorderFactory.createMatteBorder(0, 2, 2, 0, borderColor)
	elif rowIndex == 0 and colIndex == (self.data.columnCount-1):
		border = BorderFactory.createMatteBorder(0, 0, 0, 2, borderColor)
	elif rowIndex == (self.data.rowCount-1) and colIndex == (self.data.columnCount-1):
		border = BorderFactory.createMatteBorder(0, 0, 2, 2, borderColor)	
	elif rowIndex == (self.data.rowCount-1) and colIndex == 0:
		border = BorderFactory.createMatteBorder(0, 2, 2, 0, borderColor)
	elif rowIndex == 0:
		border = BorderFactory.createMatteBorder(0, 0, 0, 0, borderColor)
	elif rowIndex == (self.data.rowCount-1):
		border = BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor)
	elif colIndex == 0:
		border = BorderFactory.createMatteBorder(0, 2, 0, 0, borderColor)
	elif colIndex == (self.data.columnCount-1):
		border = BorderFactory.createMatteBorder(0, 0, 0, 2, borderColor)
	else:
		border = BorderFactory.createMatteBorder(0, 0, 0, 0, borderColor)
	return  {'border': border}

Result:
image

why is it like that? i put your code in my sample power table and just change the color.
image

The white border still showing and also not the outside border change. I want to change the white outside border color.

I see what you mean. I set my background to black and set my border to blue, and I am able to replicate the problem, but only when the app doesn't have focus.

With Focus:
image

Without Focus:
image

I'm not sure what's causing that, but if I figure something out, I will post it here.

1 Like

Making the background transparent didn't fix it. It looked like it had worked, but clicking around, the unwanted outline reappeared

i see. if you figure something out just post it here. Thanks btw for helping me! much appreciated.

1 Like

This line of code fixes the problem:
self.setBorder(None)

The table comes with a javax.swing.plaf.synth.SynthBorder that causes the observed effect. The above code simply removes it from the table.

In testing, I disabled the border code in the two extension functions, and then set the border directly from a button using the following code:

component = event.source.parent.getComponent('Power Table')
from javax.swing import BorderFactory
from java.awt import Color
border = BorderFactory.createLineBorder(Color.red)
component.setBorder(border)

This was the result:
image

This should work from the table's initialize extension function by changing the the first line to component = self, but that extension function won't fire from the designer, so an actual session will be needed to test it.

Edit: Noticed the Color import was somehow missing from the script

2 Likes

thank you!! this works for me!

1 Like