I have a JScrollPane whose content pane is a JXList. When I use the mouse wheel on the list, the list steps three (3) items at a time. This also works for a table, regardless of row height. How can I change this so that – regardless of platform – for both list and table the scroll distance is exactly 1 item? Setting block increment doesn’t cut it because some rows in the table have a different height.
Share
Out of pure interest (and a little boredom) I created a working example:
The real magic is done in the custom
AdjustmentListener, where we go and increase the current “scroll-position” by one single block per time. This works up and down and with different row-sizes, as shown in the example.As @kleopatra mentioned in the comments, you can also use a
MouseWheelListenerto only redefine the behavior of the mouse-wheel.See the official tutorial here.