How to use my trackpad for horizontal mousewheel scrolling in a Java AWT ScrollPane
Posted
by blissapp
on Stack Overflow
See other posts from Stack Overflow
or by blissapp
Published on 2010-05-16T10:18:00Z
Indexed on
2010/05/16
10:20 UTC
Read the original article
Hit count: 321
Like many modern mice and trackpads, my laptop supports vertical and horizontal scrolling. It's an addictive feature once you get used to it. I simply want my Java apps to support horizontal scrolling via the trackpad/mousewheel, but everywhere I search it seems that this is not possible in Java.
I really want someone to tell me that I'm somehow doing it wrong, this feature is already requested behaviour: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6440198
The inability to do this simple thing is actually a deal breaker for the app I'm working on. In fact, for any app I can envision! I've invested a bit of time in the Java backend, so I'd really like to find a solution for this seemingly simple thing.
Question is what could I do to implement this behaviour? Are raw OS level events even exposed to java, would I then need to write this from scratch?
import java.awt.*;
public class ScrollExample extends Canvas {
public void paint(Graphics g) {
g.setColor(Color.green);
g.fillOval(0,0,400, 400);
}
public static void main(String[] args) {
ScrollExample b = new ScrollExample();
Frame f = new Frame ("Scroll Example");
ScrollPane scroller = new ScrollPane (ScrollPane.SCROLLBARS_ALWAYS);
scroller.add(b,"Center");
f.setPreferredSize(new Dimension(500,500));
f.add ("Center",scroller);
f.pack();
f.show();
}
}
© Stack Overflow or respective owner