与JTable中的单元格渲染器的交互

编程入门 行业动态 更新时间:2024-10-27 22:22:08
本文介绍了与JTable中的单元格渲染器的交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有任何方法可以使单元格渲染器响应鼠标事件(例如鼠标悬停)?

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中的单元格渲染器的交互

本文发布于:2023-11-23 02:03:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619694.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元格   渲染器   JTable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!