Thank you, I've already got an implementation of what I have (extending TableView), and it works pretty much the same way you explained. I was not sure about the issue with the scroll pane, since I had not done any test, but after reading your email I tried it and you are right, no problems for using the scrollpane. I have some suggestions and components I would like to share in order to improve (and make it faster) development using pivot (visualizer is a useful one). I'll post everything as soon as I finish the project I'm working on.

Thanks for the suggestion,
Edgar Merino





Todd Volkert escribió:

        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

Reply via email to