Bo Master Doll also wrote several BlackBerry development of small documents, quite practical, thanks.
Original:
http://doll.javaeye.com/blog/569457
LabelField TestLabel = new LabelField (
"I swear to God up in the sky I'll be your shelter if you cry cause your are my everything."
field.focusable) {
int Currentchar = 0;
String currenttext = null;
Font Ourfont;
Private Timer _scrolltimer;
Private TimerTask _scrolltimertask;
protected void Paint (Graphics Graphics) {
Currenttext = This.gettext ();
if (Currentchar < Currenttext.length ()) {
Currenttext = currenttext.substring (Currentchar);
}
Graphics.drawtext (currenttext, 0, 0, drawstyle.ellipsis, Display
. getwidth ());
}
protected void layout (int width, int height) {
Ourfont = This.getfont ();
SetExtent (Display.getwidth (), Ourfont.getheight ());
}
protected void Ondisplay () {
Startscroll ();
}
protected void Onunfocus () {
Startscroll ();
}
private void Startscroll () {
Start scrolling
Final String fulltext = This.gettext ();
if (_scrolltimer = = null) {
_scrolltimer = new Timer ();
_scrolltimertask = new TimerTask () {
public void Run () {
Currentchar = Currentchar + 4;
if (Currentchar > Fulltext.length ()) {
Currentchar = 0;
}
Invalidate ();
}
};
_scrolltimer.scheduleatfixedrate (_scrolltimertask, 500, 500);
}
}
protected void onfocus (int direction) {
if (_scrolltimer!= null) {
_scrolltimertask.cancel ();
_scrolltimer.cancel ();
_scrolltimer = null;
_scrolltimertask = null;
}
}
protected Boolean navigationmovement (int dx, int dy, int status,
int time) {
Currenttext = This.gettext ();
int Oldcurrentchar = Currentchar;
if (math.abs (dx) > Math.Abs (dy)) {
Horizontal Scroll
if (dx > 0) {
Currentchar = Math.min (Currenttext.length ()-1,
Currentchar + 1);
else if (DX < 0) {
Currentchar = Math.max (0, currentChar-1);
}
if (Oldcurrentchar!= Currentchar) {
This.invalidate ();
}
return true;
} else {
return super.navigationmovement (dx, dy, status, time);
}
}
};