Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (512)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How do scrollbars work?  (Read 1328 times)
0 Members and 1 Guest are viewing this topic.
Offline Renoria

Junior Duke




...


« Posted 2009-04-09 04:31:15 »

I need to know how scrollbars work because the Built in java scrollbars aren't good enough for what I need. I need to know how to calculate the (ratio?) of the viewing area and when you drag the bar, how does it change the view? Any custom scrollbar examples?

Thanks.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #1 - Posted 2009-04-09 06:57:26 »

It's pretty simple.

You need to know:
1) How big your viewing area is.
2) How big your content within the viewing area is.
3) How long the scrollbar pane is (not the slidey part, but the place that can get slid around in).
4) What position the content is currently at.

Then it's all a matter of simple ratio calculation.

Let's just do this with height for now.

ratio = view.height / content.height
scroller.height = scrollpane.height * ratio
scrollRatio = scroller.y / scrollpane.height
content.y = scrollRatio * content.height

And voila.


See my work:
OTC Software
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #2 - Posted 2009-04-09 11:32:20 »

You may also be using the scrollbars incorrectly.  What are you trying to do?  I have used them before and they worked for me.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Renoria

Junior Duke




...


« Reply #3 - Posted 2009-04-10 05:52:21 »

I'm not using JScrollBar, I'm implementing my own
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2009-04-10 07:39:05 »

Then it's all a matter of simple ratio calculation.

Let's just do this with height for now.

ratio = view.height / content.height
scroller.height = scrollpane.height * ratio
scrollRatio = scroller.y / scrollpane.height
content.y = scrollRatio * content.height


Not quite, you forgot a tiny little thing:

ratio = view.height / content.height
scroller.height = scrollpane.height * ratio
scrollRatio = scroller.y / (scrollpane.height - scroller.height)
content.y = scrollRatio * content.height

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #5 - Posted 2009-04-10 07:56:01 »

Yeah you're right. I just threw that up there quickly. Plus I said "4) What position the content is currently at." but really I meant "4) What position the scrollbar is currently at."

See my work:
OTC Software
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #6 - Posted 2009-04-11 05:21:58 »

I'm not using JScrollBar, I'm implementing my own

But you might be able to use JScrollPane.  You said the built in ones are not good enough, so I am asking what you are trying to do to see if you can use the built in ones.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (50 views)
2014-10-17 03:59:02

Norakomi (39 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (36 views)
2014-10-15 16:18:58

TehJavaDev (66 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!