This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to scroll with the mouse horizontally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to scroll with the mouse horizontally" Watch "How to scroll with the mouse horizontally" New topic
Author

How to scroll with the mouse horizontally

Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

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


Olly
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
use a scrollpane and set vertical to never, then set horizontal scrollbar height to 0
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Oct 27, 2005
Posts: 19651
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to scroll with the mouse horizontally
 
Similar Threads
body onload() alternative
TextFields and TextArea, cols parameter,
Urgent
how to use dataTable without scrolling header
how to auto scroll to see the bottom of the jtextarea?