TabbedPaneUI: When the mouse wheel event is not in the viewport, propagate the event to the nearest parent #1030
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
I would like to propose a change to the handling of mouse wheel events in the TabbedPane when the event did not occur in the viewport.
The scenario is the following: A JTabbedPane with tab layout policy = SCROLL placed inside a JScrollPane.
If the content of the open tab or of the scroll pane itself are too large to show, the expected behavior is that mouse wheel events cause the outer ScrollPane to scroll - unless the mouse wheel event occurred within the viewport of the TabbedView, in which case the tabs may scroll.
However, the event dispatching retargets the event only to the nearest surrounding component that can handle mouse wheel events, which in case of FlatLaF is the TabbedPane since it brings its own mouse wheel listener. That listener checks if the event is within the viewport, and if it is not, does nothing. The event is also dispatched to the ancestor (Window), which does nothing with it as well. The outer ScrollPane never receives the event.
The proposed fix redirects events outside of the viewport to the nearest parent container that has a mouse listener.
I have not actually compiled it into FlatLaf, but I have tested it by implementing my own MouseWheelListener on a JTabbedPane (with a hacky workaround that removes and adds the additional listener in order to be able to trigger the FlatTabbedPaneUI implementation when needed).
The condition might also need to be refined to ignore other ScrollPanes with FlatTabbedPaneUI found among the parent containers.
with best regards