Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to scroll with the mouse horizontally

 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy folks

According to this thread the MouseWheelEvent class doesn't support horizontal scrolling. I've looked through the Java API and Google for alternatives but no luck.

Suggestions?

NOTE: I'm fairly sure it should be possible. Scrolling horizontally with the mouse works within a JScrollPane.

Thank-you
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use a scrollpane and set vertical to never, then set horizontal scrollbar height to 0
 
Rob Camick
Ranch Hand
Posts: 2542
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:use a scrollpane and set vertical to never, then set horizontal scrollbar height to 0


You don't need to set the horizontal scrollbar height to 0. At least not with the Metal LAF on JDK6. Unless, of course, your goal is to hide the horizontal scrollbar.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Unless, of course, your goal is to hide the horizontal scrollbar.

yes.

the OP states horizontal scrolling in a scrollpane is fine,
so I guessed perhaps he wants something without the scrollbar showing.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Olivier simply wants to get an event when the user scrolls horizontally. For vertical scrolling there is MouseWheelListener with MouseWheelEvent, but there is no such thing for horizontal scrolling yet. There's already an accepted but unsolved bug report for that.

If the component itself supports horizontal scrolling then you can use an AdjustmentListener on the JScrollPane's horizontal scroll bar. This will be notified when the scroll bar's position changes, a side effect of the scrolling.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I think Olivier simply wants to get an event when the user scrolls horizontally.

probably is what he wants, I was more going by his subject line "How to scroll with the mouse horizontally"

I still don't see the his problem though, the mouseWheelListener works for horizontal scolling, if there's
no vertical scrollbar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic