Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we create IPhone scrolling in JTable using Swing?

 
Aji Sree
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can we create IPhone scrolling in touch screen using Swing?

I have a JTable in which I want to implement this function without using the scroll arrows of Scroll bar.

The things that happens in IPhone are

- Keep finger on screen --> lists scrolls up and down, slow and fast according to finger movement (1:1).

- Move finger over screen for a short distance and detach finger from screen --> List scrolls a little (slow) and then slows down and finally stops.

- Move finger over screen for a long distance and detach finger from screen --> List scrolls a lot (fast) and then slows down and finally stops.

Thanks in advance
Ajith.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of device is this code supposed to run on? Does it have a touch screen?
 
Aji Sree
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Of course. It should work in a touch screen.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of API is supported by the device? Is it something that's attached to a desktop machine, or a mobile device?
 
Aji Sree
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not a mobile device. It is a touch screen on a desktop machine.

What I am not getting is How can I relate the distance with the speed of scrolling. When I scroll long it should scroll fast and when takes the finger from screen scrolling should become slow and finally stop.
If I am scrolling short the list should scroll slow and when takes finger it should scroll slow and finally stop.

Thank you
 
Rob Camick
Ranch Hand
Posts: 2599
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I have no idea what your API is like but presumably you have something like the MouseListener API.

So when you have a mousePressed event you track the point the mouse was pressed. When you get a mouseDragged event you start a Timer to do scrolling at a specified interval. As the dragged distance increases you increase the amount of each scroll. When you get a mouseReleased, you stop the Timer. So the basic trick is in calculating the scroll distance and/or frequency based on the dragged distance.
 
Aji Sree
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

Thank you very much for the help. I tried it in that way and the scrolling while dragging and on the mouse released event works now.
Also it scrolls fast and slow according to the distance of the scrolling.

But

- Move finger over screen for a long distance and detach finger from screen --> List scrolls a lot (fast) and then slows down and finally stops.

I am not getting the effect that is described in blue color.

Can anybody help in this issue?

Thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, of course, when you release your finger, you need to have a thread running that sends a few more events. You might do it with the same sort of timer -- a new one that you start when the finger comes off.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic