Mouse Cursor point to hand change over specific cell?

Does anyone know a way to force the mouse cursor to change from pointer to hand over specific cells in the power table.

I’m using two columns for navigation. I am trying to get the cursor to change so the operator knows what is clickable vs not.

Any input is appreciated.

Thanks.

This could have been easy if there were an extension function onMouseMovedCell() on power table. Since each cell has its own event listener, the event handler exposed mouseMoved() won’t be useful so we’re forced to use another approach.
The fast solution I can think is on a client event script with a fast rate execution of 200 millis or so and dedicated thread.
The script should look like this:

def setCursorTable(jtable): 
	from java.awt import MouseInfo, Point, Cursor
	pointerLocation = MouseInfo.getPointerInfo().getLocation() 
	table = jtable.getTable()
	relativeX = pointerLocation.x-table.getLocationOnScreen().x 
	relativeY = pointerLocation.y-table.getLocationOnScreen().y 
	tablePoint = Point(relativeX,relativeY) 
	rowPointIdx = table.rowAtPoint(tablePoint)
	colPointIdx = table.columnAtPoint(tablePoint)
	if rowPointIdx != -1 and colPointIdx != -1:
		#add more column index conditions
        if colPointIdx == 0: #0 index column
			jtable.setCursorCode(Cursor.HAND_CURSOR)
		elif colPointIdx == 1: #1 index column
			jtable.setCursorCode(Cursor.DEFAULT_CURSOR)
	
windowPath = "Main Window" #your windows path where your table is located
tableName = "Power Table" #your table name component
try:
	window = system.gui.getWindow(windowPath)
	jtable = window.getRootContainer().getComponent(tableName)
	setCursorTable(jtable)
except:
	system.util.getLogger('jtableCursor').info('no window opened or not component found.')

and this in mouseEntered() event handler power table

from java.awt import Cursor
event.source.setCursorCode(Cursor.DEFAULT_CURSOR)

You should monitor the performance of the client.

1 Like

@jespinmartin1 Thanks for the quick response I will implement this and let you know how it worked. Thanks.

it works, I did it. Tell me if you need some help.

Potentially easier, probably more performant, would be to return a custom renderer for each cell/column, with the appropriate cursor selected. The tricky part then becomes the actual rendering; javax.swing.table.DefaultTableCellRenderer is just a wrapped JLabel, so it may not have the ‘right’ appearance without further customization.

@jespinmartin1

I’m having issues.

I’ve implemented the above script in the local functions under scripting

I put the below code in the mounsEntered() event handler

I adjusted the window path and table name.

I don’t get any error codes of any sort but not cursor change

any ideas I might try?

Thanks again for all your help

@PGriffith thanks for the input. I’ll be honest a bit above my head but I appreciate the response and will put in the time and research into your input thanks.

Is “local function” equivalent to you to Client Event Script with 200ms timer?
Can you create a new client script with maybe 1sec rate:

print "I'm a client script"

And see the output at the client console?
Did you changed the colPointIdx Conditions applied to your case?

Eh, my approach doesn’t work anyways; it doesn’t seem to render the different cursor.
For posterity:

	if colName == "String Column":
		from javax.swing.table import DefaultTableCellRenderer
		from java.awt import Cursor 
		renderer = DefaultTableCellRenderer()
		renderer.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR))
		renderer.setValue(textValue)
		return {'renderer': renderer}
1 Like

@jespinmartin1 Your solution worked I didn’t place your code in the Client Event Script. I put the code in the “Project Library” under scripting.

Thanks for your help and follow up.

For anyone who’s interested, I took a slightly different approach and was able to get things to work in what I believe to be a straightforward, performant way.

NOTE: I make no guarantees about this code. It might have bugs, and it almost surely could be optimized or made more elegant in some way.

I put this class definition in a shared library that happens to be named “Utils” in my project:

from java.awt.event import MouseMotionAdapter
from com.jidesoft.grid import TableModelWrapperUtils
from java.awt import Cursor
		
class CellMotionListener(MouseMotionAdapter):
	def __init__(self, colNames, cursor):
		MouseMotionAdapter.__init__(self)
		
		self.colNames = colNames if isinstance(colNames, (tuple, list)) else []
        self.ccursor = cursor
	
	def mouseMoved(self, e):
		arow = TableModelWrapperUtils.getActualRowAt(e.source.model, e.source.rowAtPoint(e.point))
		acol = TableModelWrapperUtils.getActualColumnAt(e.source.model, e.source.columnAtPoint(e.point))
		
		#Traverse back to the VisionAdvancedTable component
		vat = e.source.parent.parent
		
		#Use the helper method to get the actual column index in the "data" attribute
		colName = vat.data.getColumnName(vat.columnIndexToDatasetIndex(acol))
		
		if colName in self.colNames and vat.data.getValueAt(arow, colName) is not None:
			if e.source.cursor.type != self.ccursor:
				e.source.cursor = Cursor.getPredefinedCursor(self.ccursor)
		else:
			if e.source.cursor.type != Cursor.DEFAULT_CURSOR:
				e.source.cursor = Cursor.getDefaultCursor()

Then, in the “Initialize” Extension Function on my Power Table, I put this code. In my case, I want the “hand” icon to appear when the user mouses over a column named “email” in the underlying dataset, to indicate that it’s a “link” that could be clicked on. I used the literal form of a single-element tuple (since I only care about one column), but you could potentially have more columns that you might want the “hand” cursor for. You could also specify a different cursor type here as well.

from java.awt import Cursor

table = self.getTable() 
table.addMouseMotionListener(Utils.CellMotionListener(('email',), Cursor.HAND_CURSOR))

It feels a bit clunky to be setting the cursor for the entire table, but it seems to perform well.