Power Table OnMouseClick Cell Color Change

Hi, I want to change PowerTable cell bckcolor on mouse click event. Event called but color not change.
Any one can have idea??'

def onMouseClick(self, rowIndex, colIndex, colName, value, event):
	# put your code here
	if colName == "c1":	
		print "From onMclick"
		return {"background":"FDC754"}

Mouse click events are not expected to return anything. This cannot work. You need to write into the table's style for that cell.

In vision, you have to put such dynamic styling into a custom property of the component where it can be retrieved by the configureCell method. Only configureCell can return a style.

I can not understand. Bcz its PowerTable where i can find the table style???

Ok. But how can i get mouseclick event in configureCell. I want to change cell background color onMouseclicked event.
and also add how can i change cell value onMouseClicked event.

Can we call configureCell in mouseclick event???

Hi, Please help that, is it possible???

You cannot directly change the cell color from the mouse event. You must store your styling information in a custom property (perhaps another dataset with the same dimensions as your table data). The mouse event can only update that custom property.

The configure cell method is called automatically by the component whenever java swing needs to "paint" that cell. Have that method look up the desired color in the custom property and return that.

Changing a custom property is one of the triggers that causes Swing to repaint, so the mouse click updating a custom property will naturally cause the configureCell method to be called shortly.

(configureCell is called really often--any time the table is obscured by something then unobscured, it has to be repainted. Java takes care of this, by you must have the styling data hanging around.)

1 Like

If you only ever want the one selected row/cell to be the special color, consider not using a mouse click at all. Just have configureCell check if selectedRow and selectedColumn match the values handed to it.

1 Like