JTable Scrolling by Mouse Position
Is it possible to have the rows in a JTable scroll depending on mouse position?
i.e. if the cursor is nearin开发者_如何学JAVAg 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).
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.
精彩评论