From 8cfe1ca5972a81b2060d6ea44b678792963e5a89 Mon Sep 17 00:00:00 2001 From: lkrieger-oashi Date: Wed, 20 Aug 2025 10:17:01 +0200 Subject: [PATCH 1/2] changed: when the mouse wheel event is not in the viewport, propagate the event to the nearest parent Scenario: A JTabbedPane inside a JScrollPane Expectation: Moving the mouse wheel inside the TabbedPane's content should cause the outer ScrollPane to scroll Actual: Event dispatcher targets TabbedPane, but the TabbedPane's mouse listener does nothing because the event is not in the viewport. The only other target is the ancestor (Window), which discards the event. Fix: If the event does not occur in the viewport, delegate it up in the hierarchy to the nearest parent with a MouseWheelListener --- .../com/formdev/flatlaf/ui/FlatTabbedPaneUI.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java index d4e866f3..bc872f83 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java @@ -2707,8 +2707,22 @@ debug*/ // because this listener receives mouse events for the whole tabbed pane, // we have to check whether the mouse is located over the viewport - if( !isInViewport( e.getX(), e.getY() ) ) + if( !isInViewport( e.getX(), e.getY() ) ) { + // if it is not in the viewport, retarget the even to a parent container + // which might support scrolling (e.g. a surrounding ScrollPane) + Container parent = getParent(); + while (parent != null) { + // informing the first parent with a mouse wheel listener should be sufficient. + if (parent.getMouseWheelListeners().length > 0) { + for (MouseWheelListener parentListener : parent.getMouseWheelListeners()) { + parentListener.mouseWheelMoved(e); + } + return; + } + parent = parent.getContainer(); + } return; + } lastMouseX = e.getX(); lastMouseY = e.getY(); From b9441050b22cdfcf0ba281548ae3d87bc3ad3675 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sat, 29 Nov 2025 23:12:21 +0100 Subject: [PATCH 2/2] TabbedPane: - convert mouse wheel event before dispatching it to parent - use `Component.dispatchEvent()`, instead of invoking mouse wheel listeners directly, which dispatches the event to an ancestor --- .../com/formdev/flatlaf/ui/FlatTabbedPaneUI.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java index bc872f83..ab869fcb 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java @@ -2708,19 +2708,10 @@ debug*/ // because this listener receives mouse events for the whole tabbed pane, // we have to check whether the mouse is located over the viewport if( !isInViewport( e.getX(), e.getY() ) ) { - // if it is not in the viewport, retarget the even to a parent container + // if it is not in the viewport, retarget the event to a parent container // which might support scrolling (e.g. a surrounding ScrollPane) - Container parent = getParent(); - while (parent != null) { - // informing the first parent with a mouse wheel listener should be sufficient. - if (parent.getMouseWheelListeners().length > 0) { - for (MouseWheelListener parentListener : parent.getMouseWheelListeners()) { - parentListener.mouseWheelMoved(e); - } - return; - } - parent = parent.getContainer(); - } + Container parent = tabPane.getParent(); + parent.dispatchEvent( SwingUtilities.convertMouseEvent( tabPane, e, parent ) ); return; }