Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Contributor
Posts: 7
Registered: ‎04-15-2010
My Device: 9530
My Carrier: simulater

Scrollbar Component in Blackberry



I am developing a Blackberry application, In that I need a vertical scrollbar.


Always vertical scrollbar should follow the cursor.




Always vertical scrollbar should be at the bottom of the screen.


How should we achive this. Presently I am using with LWUIT for this.


Please help me on this


Thanks in advance

BlackBerry Development Advisor
Posts: 15,888
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Scrollbar Component in Blackberry

You can use a VerticalFieldManager with scrolling enabled (styles VerticalFieldManager.VERTICAL_SCROLLBAR and VerticalFieldManager.VERTICAL_SCROLL).

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Scrollbar Component in Blackberry

As MSohm pointed out, VERTICAL_SCROLL and VERTICAL_SCROLLBAR provide some basic functionality.  If you create a VerticalFieldManager with those two styles it will display a small triangle in the upper right corner if there is more content above the visible area and a small triangle in the lower right corner if there's more content below it.


If you want to do anything fancier, though, you'll have to override the VerticalFieldManager's paint() and possibly sublayout().


1.  Choose an area on the right (left?) where you would like to display the slider.  I use a few private final static int constants like: SCROLLBAR_WIDTH, SCROLLBAR_RIGHT_MARGIN (if you don't want it to be hugging the right side of the VerticalFieldManager) as well as SCROLLBAR_COLOR and SCROLLBAR_SLIDER_COLOR.  Hope the names are self-explanatory.Smiley Wink

2.  Calculate the height of the slider (better do it once in sublayout() like this):


private int sliderHeight;
protected void sublayout(int w, int h) {
    super.sublaout(w, h);
    int fullHeight = getVirtualHeight();
    int visibleHeight = getVisibleHeight();
    sliderHeight = visibleHeight * visibleHeight / fullHeight;
    if (sliderHeight == 0) {
        sliderHeight = 1;  // would like to make it visible!



3. In paint(), add painting of the slider:


protected void paint(Graphics g) {
    int scrollPosition = getVerticalScroll();
    int scrollbarX = getVisibleWidth() - SCROLLBAR_WIDTH - SCROLLBAR_RIGHT_MARGIN;
    int scrollbarHeight = getVisibleHeight();
    int sliderPosition = (scrollPosition * scrollbarHeight) / getVirtualHeight();
    // Draw scrollbar "background"
    g.fillRect(scrollbarX, scrollPosition, SCROLLBAR_WIDTH + SCROLLBAR_RIGHT_MARGIN, scrollbarHeight);
    // Draw "slider"
    g.fillRect(scrollbarX, scrollPosition + sliderPosition,
               SCROLLBAR_WIDTH, sliderHeight);

 If you ever manually set vertical scroll with VerticalFieldManager.setVerticalScroll(), don't forget to invalidate()!





please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!