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

How to support hot keys: Press t (scroll to top) and b (scroll to bottom)

by BlackBerry Development Advisor on ‎03-14-2011 04:54 PM (5,331 Views)



This article applies to the following:


  • BlackBerry® smartphones based on Java® technology




Many of the core BlackBerry Applications support hot keys that perform a specific action within the application.  A common pair of hot keys are the t and b keys, which cause the screen to jump to the top and bottom of the current screen.  The following custom manager demonstrates how this can be implemented within your application.



package com.hyves.bb.general.ui.component;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.container.VerticalFieldManager;

* VerticalFieldManager that has functionality for (t)op and (b)ottom jumping behaviour.
* This only works if the keyChar was not consumed by something else. So if there is another
* component consuming the keypress t or b then it will not work. But that is intended.
* @author Tjerk Wolterink tjerkw@gmail.com
public class TopBottomVerticalFieldManager extends VerticalFieldManager {

public TopBottomVerticalFieldManager(long style) {

* Implementation of (t)op and (b)ottom jumping behaviour
public boolean keyChar(char ch, int status, int time) {
if(super.keyChar(ch, status, time)) {
// event was consumed
return true;
if(ch == 't') {
// move to top
Field f = this.getField(0);
if(f!=null) {
return true;

} else if(ch == 'b' && this.getFieldCount()>0) {
// move to bottom
Field f = this.getField(this.getFieldCount()-1);
if(f!=null) {
int pos = getVirtualHeight() - getVisibleHeight();
if (pos < 0) {
pos = getVisibleHeight();
return true;
return false;
by Developer
on ‎03-20-2011 09:20 AM

Thank you, very useful!

Users Online
Currently online: 12 members 815 guests
Please welcome our newest community members: