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)
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.
@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.
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.