I have the following Swing UI structure.
When I scroll the mouse wheel within the blue JPanel, the JScrollPane doesn't respond to the mouse wheel event. Why?
I read from the java doc that:
JScrollPane provides a scrollable view of a lightweight component. ... Note that JScrollPane does not support heavyweight components.
So is this because my structure is too heavy? Or any other reasons?
ADD 1
I accidentally switched my window with the mouse middle click. And after that, the mouse wheel suddenly worked for the JScrollPane.
This leads me to think maybe it's related to the focus
. Then I found below line:
this.setFocusableWindowState(false);
After I changed it to below, mouse wheel works.
this.setFocusableWindowState(true);
Though javadoc says:
Setting a Window's focusability state to false is the standard mechanism for an application to identify to the AWT a Window which will be used as a floating palette or toolbar, and thus should be a non-focusable Window.
At first, I guess it's because the JDialog is not in focusable window state, so it cannot receive events. But actually, mouse click always works. So I am still not sure about the root cause.
It seems a toolbar or a floating palette cannot be focused but still can receive mouse click event. So I guess maybe only certain events are filtered by setFocusableWindowState(false)
.