> > So the question is, is there a simpler way to attach listeners to >> cellrenderer components? >> > > No. Since the renderers aren't really "there" (they are not part of the > component hierarchy), they don't receive mouse events. You can do this by > listening for mouse events on the TableView itself and translating to the > renderer space. When the table view is in a scroll pane, you can use the > getScrollTop() and getScrollLeft() methods of ScrollPane to determine the > offset into the table view's coordinate space.
If a TableView is the right tool here (vs TablePane), then registering a mouse listener on the TableView should sidestep any issues with a ScrollPane, since the mouse coordinates will already be in the TableView's coordinate space. Then you can call TableView.getRowAt(int y) and TableView.getColumnAt(int x) to find out which cell you're over. You might do this if you had a column that contained a "delete" icon, where a click in that column would remove the row. If that column has multiple buttons, then once you've gone that far, you can then hook into your custom cell renderer to find out which actual button the mouse is over (you'll have to provide something like CustomCellRenderer.getButtonAt(int x)). This is all for responding to mouse clicks over a cell. If you want to repaint the cell differently as the user mouses over it, you can use the same principles, but it'll be a little more complicated because you'll have to trigger the repaints and know how to paint the correct state in the renderer. -T
