JTable 按鼠标位置滚动
JTable 中的行是否可以根据鼠标位置滚动?
即,如果光标接近表格顶部,则开始向上滚动,如果光标接近表格底部,则开始向下滚动。
类似于as3中的这种效果:
http://activeden.net/ item/professional-dock-menu-as2-and-as3/127450
我当前正在使用:
int row = table.rowAtPoint(e.getPoint());
Rectangle r = table.getCellRect(row,0,true);
table.scrollRectToVisible(r);
在 mouseMoved 侦听器中,当光标到达顶部/底部行时滚动一次。我不确定如何让它在这之后继续滚动(目前用户必须不断移动鼠标才能让它继续滚动)。
Is it possible to have the rows in a JTable scroll depending on mouse position?
i.e. if the cursor is nearing the top of the table, it begins to scroll upward, and if it is nearing the bottom of the table, it begins to scroll downward.
Similar to this effect in as3:
http://activeden.net/item/professional-dock-menu-as2-and-as3/127450
I'm currently using:
int row = table.rowAtPoint(e.getPoint());
Rectangle r = table.getCellRect(row,0,true);
table.scrollRectToVisible(r);
within a mouseMoved listener, which scrolls once when the cursor gets to the top/bottom row. I'm unsure how to get it to keep scrolling after this though (currently the user would have to continually move the mouse around to get it to keep going).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你需要在鼠标进入表格时启动 Swing 计时器。在 mouseMoved 事件中,您可以更改计时器间隔,使其更快或更慢,具体取决于鼠标相对于桌面/底部的位置。然后,当计时器触发时,您可以使用 MouseInfo 类(或保存最后一个 mouseMoved 点)来获取鼠标位置,以确定是否向上/向下滚动一行。
I would guess you need to start a Swing Timer when the mouse enters the table. On a mouseMoved event you can change the Timer interval to make it faster or slower depending on where the mouse is relative to the table top/bottom. Then when the Timer fires you can use the MouseInfo class (or save the last mouseMoved point) to get the mouse location to determine whether to scroll up/down one row.