This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Can we create IPhone scrolling in JTable using Swing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can we create IPhone scrolling in JTable using Swing?" Watch "Can we create IPhone scrolling in JTable using Swing?" New topic
Author

Can we create IPhone scrolling in JTable using Swing?

Aji Sree
Greenhorn

Joined: Jun 19, 2009
Posts: 18
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
Marshal

Joined: Mar 22, 2005
Posts: 41180
    
  45
What kind of device is this code supposed to run on? Does it have a touch screen?


Ping & DNS - my free Android networking tools app
Aji Sree
Greenhorn

Joined: Jun 19, 2009
Posts: 18
Yes. Of course. It should work in a touch screen.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41180
    
  45
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

Joined: Jun 19, 2009
Posts: 18
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

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

Joined: Jun 19, 2009
Posts: 18
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can we create IPhone scrolling in JTable using Swing?
 
Similar Threads
Showing 300000+ records in JTable
Scroll using fingers in a touch screen
Java JTable Screen Blink Problem
Problem with JTable
JTable Paging