是否有任何方法可以使单元格渲染器响应鼠标事件(例如鼠标悬停)?
Is there any way to get a cell renderer to respond to mouse events, such as mouseovers?
推荐答案从未尝试过,但我想您需要:
Never tried it but I guess you would need to:
a)创建一个自定义渲染器,以两种状态绘制单元格
a) create a custom renderer to paint the cell in two states
b)您需要跟踪当前应在鼠标悬停"状态下绘制哪个单元格
b) you need to keep track of which cell should currently be painted in the "mouse over" state
c)添加鼠标侦听器,以跟踪输入/退出的鼠标和mouseMoved的鼠标.对于每个事件,您都需要更新一个变量,以跟踪鼠标置于哪个单元格上.你 可以使用JTable的columnAtPoint()和rowAtPoint()方法
c) add a mouse listener to track mouse entered/exited and mouseMoved. With each event you would need to update a variable that tracks which cell the mouse is positioned over. You can use the columnAtPoint() and rowAtPoint() methods of JTable
d)当鼠标离开一个单元格时,您需要在该单元格上调用repaint().您可以使用getCellRect()方法来确定要重绘的单元格
d) when the mouse leaves a cell you need to invoke repaint() on the cell. You can use the getCellRect() method to determine which cell to repaint
e)当鼠标进入一个单元格时,您需要将单元格值重置为鼠标悬停"状态,然后重新绘制该单元格.
e) when the mouse enters a cell you need to reset the cell value for the "mouse over" state and then repaint the cell.
更多推荐
与JTable中的单元格渲染器的交互
发布评论