A few years ago Apple introduced multi-touch functionality to the trackpads in their laptops. Undoubtedly the most used gesture is placing two fingers on the pad and moving them around to scroll. If you remove your fingers while still moving, the content obeys the laws of momentum, flying across the screen before gradually slowing to a halt.
The view on-screen moves perfectly with your fingers – after a while it becomes completely subconscious, and scrolling any other way fails to cross your mind.
The only problem with this is that it’s a fundamentally different model of scrolling to that used on a normal mouse. Normal mice use notches – you pull or push at the wheel until it snaps into the next notch, and the view jumps up or down. On Apple’s trackpads, though, no such notches exist – or if they do, they’re too small for you to notice them.
When writing their JREs for OSX, Apple and Oracle had a problem – how do you deal with an input device which works so differently? Well, they chose to stick their fingers in their ears and pretend it doesn’t. There’s no official support for multi-touch in Java as of yet, so it’s all been run through the usual Java MouseListener model. This means several things:
- Whereas in most applications on OSX you can scroll in two dimensions, in Java applications you can only scroll up or down.
- Old style jumps replace the smooth scrolling experience.
- All uses of the “scroll wheel” obey the laws of momentum, whether it’s actually being used for scrolling or not.
We also use the scroll wheel for zooming and changing pages, which presents us with a problem. If you are at the bottom of the page and scroll down, it’s obvious that you want to go to the next page. However, if you’re at the top of the page and fling downwards, you probably want to see the bottom of the current page and not advance to the next. The problem is that Java doesn’t allow you to distinguish between these distinct events – they are identical from the code’s perspective.
With the possible long-term replacement of Swing for JavaFX, it seems to me like it would be a good idea to get multi-touch support into JavaFX as soon as possible – or at least some simple way of detecting whether a scroll event is coming directly from a user or from the simulated momentum. At present it seems the mouse support on JavaFX is roughly equal to that of Swing – but if we’re getting modern graphics, shouldn’t we have modern input device support to match?
Latest posts by Sam Howard (see all)
- PDF to HTML5’s Holy Grail – Vertical positioning for PDF fonts - October 8, 2015
- WOFF 2.0: What is it, why is it coming, and what’s next? - April 2, 2015
- Web fonts: A quick introduction to Wrapper and Glyph formats - February 27, 2015
- 5 tips for using fonts in HTML5 - January 29, 2015
- A Beginners introduction to Unicode - December 4, 2014