Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,757 members, 7,824,172 topics. Date: Saturday, 11 May 2024 at 02:33 AM

A Simple Solution To J2me Scroll Bar - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / A Simple Solution To J2me Scroll Bar (816 Views)

Pagination Vs Infinite Scroll / How To Make A Simple Calculator In Notepad Using .bat Format / Help (wrap Text In J2ME & Scroll Vertically) (2) (3) (4)

(1) (Reply)

A Simple Solution To J2me Scroll Bar by elvis10ten(m): 9:57pm On Apr 29, 2013
This is a quick easy solution to creating a j2me scrollbar. It has not yet been tested, but i think it will work. The idea came when i was working with percentages.
SOLUTION
PLEASE NOTE THAT YOU MUST KNOWN THE MAXIMUM LINES. THIS CAN BE GOTTEN BY SOME MANIPULATION WITH THE FONT, STRING AND WITH A WHILE LOOP. ALL YOU HAVE TO DO IS, USE THE FONT CLASS TO DETERMINE THE TEXT THAT CAN ENTER ONE LINE. STORE THAT LINE IN A VECTOR THEN CONTINUE, TILL YOU ARE DONE WITH THE TEXT. I remember i have coded this before but this is not the point of this thread, any real j2me developer should know how to do that i guess. WHEN YOU KNOW THE MAXIMUM NUMBER OF LINES, THEN YOU MUST ALSO KNOW THE PRESENT LINE THE USER IS AT. THIS IS SIMPLE, IF YOU ARE USING A VECTOR TO STORE EACH LINE THEN USING A WHILE LOOP TO DISPLAY, THEN THE FIRST ELEMENT THAT IS PRINTED OUT IS THE CURRENT LINE, GET THE NUMBER. Then you use this:
scrollbar = (currentLine/maxLine) * (deviceWidth - scrollBarLength)
this will give you the position where your scrollbar should start(be). Lets take an example. The maximum line is 1000 and the current line is 500. The device Width is 320 and the scrollbar length is 10.
scrollbar = (500/1000) * (320 - 10)
The result is equal to 155, which is half of the screen and the user is at half of the page. So am damn sure it will work. Please note that the value you get is the starting position of the scrollbar on the y axis. The value should be convert to an int since this can give funny result. If you have any question or comment drop it here.

(1) (Reply)

I Want To Develop My First Web Application, Please I Need Your Suggestions / Kudaisi, The Man Of The Moment / Urgent; Guys Pls How Can I Restore/get A New Stock Rom For My Samsung Duos 2

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 8
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.