Suppose I have a large (the size is set using setPreferredSize) a custom widget inherited from JPanel (only the paintCompontent method is redefined for it, in which the filled rectangle is first drawn (0, 0, this.getWidth (), this.getHeight () ), and then all sorts of my objects). I wrap it in a JScrollPane to scroll. At the same time, scrolling with the help of scroll bars, as well as vertical scrolling with the mouse wheel, normally works. At my mouse wheel can not only twist, but also tilt to the right-left. However, many applications (including those using Java, for example, IDEA) recognize this as horizontal scrolling and react correctly. Similar behavior can be achieved using edge scrolling on the laptop's touchpad.
The problem is that the JScrollPane does not react to horizontal scrolling in any way - it can be done only by dragging the corresponding scrollbar, and the mouse wheel tilts (or horizontal touchpad scrolling) are completely ignored.
How to make JScrollPane support not only vertical, but also horizontal scrolling with the mouse wheel? I ran xev (I have Linux) and saw that vertical scrolling corresponds to pressing 4-5 mouse buttons, and horizontal scrolling 6-7. Can I implement horizontal scrolling on my own based on this data or the emulated mouse buttons may have different numbers? Or maybe there is a standard solution?
PS: I tried to do setWheelScrollingEnabled. As far as I understand, the default scrolling wheel is already allowed and a call with the parameter true does not change anything. If you pass false, then the vertical scrolling with the wheel on this widget is disabled.