diff --git a/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FlamegraphView.java b/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FlamegraphView.java index 28371d2..4aa07a3 100644 --- a/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FlamegraphView.java +++ b/fireplace-swing/src/main/java/io/github/bric3/fireplace/flamegraph/FlamegraphView.java @@ -28,6 +28,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; import java.awt.geom.Area; import java.awt.image.BufferedImage; import java.beans.PropertyChangeListener; @@ -1553,7 +1554,8 @@ public void zoom(@NotNull ZoomTarget<@NotNull T> zoomTarget) { * @param * @see FlamegraphView.HoverListener */ - private static class FlamegraphHoveringScrollPaneMouseListener implements MouseInputListener, FocusListener { + private static class FlamegraphHoveringScrollPaneMouseListener + implements MouseInputListener, MouseWheelListener, FocusListener { private Point pressedPoint; private final FlamegraphCanvas canvas; private Rectangle hoveredFrameRectangle; @@ -1671,6 +1673,15 @@ public void mouseExited(@NotNull MouseEvent e) { @Override public void mouseMoved(@NotNull MouseEvent e) { + handleMouseLocationChange(e); + } + + @Override + public void mouseWheelMoved(@NotNull MouseWheelEvent e) { + handleMouseLocationChange(e); + } + + private void handleMouseLocationChange(@NotNull MouseEvent e) { var latestMouseLocation = MouseInfo.getPointerInfo().getLocation(); SwingUtilities.convertPointFromScreen(latestMouseLocation, canvas); @@ -1760,6 +1771,9 @@ public void install(@NotNull JScrollPane sp) { sp.addMouseListener(this); sp.addMouseMotionListener(this); sp.addFocusListener(this); + // impl note, mouse wheel listener should be added on the scroll pane + // otherwise the scroll pane don't receive wheel events + sp.addMouseWheelListener(this); } }