Welcome!

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

Reply
Developer
pfbertrand
Posts: 32
Registered: ‎11-21-2008
My Device: Not Specified

Auto scroll down as text comes into RichTextField

I'm trying to write a sample application that has a big initialization that occurs as the app starts up and I want to display progress right away so I implemented an activate() which starts a thread that updates a RichTextField.  Is this a good practice (implementing activate()) or is there a better way?

 

So far it works fine but I can't seem to get the display to scroll down as new text is added.

 

Code was written for JDE4.1.

 


import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.i18n.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;


/**
 * Utility to dump ULJ databases to a server
 */
public final class AccessTest extends UiApplication {

    //members ------------------------------------------------------------------
    private boolean   _hasActivated = false;
    private static RichTextField _output;
    private SampleCreatorScreen  _mainScreen;

    private static class SampleCreatorScreen extends MainScreen
    {
 public SampleCreatorScreen()
 {
     super(
      DEFAULT_MENU | DEFAULT_CLOSE
      | Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR
  );

     setTitle( "Sample DB Creator" );
     _output = new RichTextField( "working..." );
     add( _output );
 }

        public boolean onClose()
        {
            Dialog.alert( "Goodbye!" );
            close();
            return true;
        }
   
 public void message(String msg)
 {
     synchronized( Application.getEventLock() ) {
  _output.setText( _output.getText() + "\n" + msg );
  //
  // Try to set focus at bottom
  //
  int v = getVirtualHeight() - getHeight();
  if( v > 0 ) {
      setVerticalScroll( 0 );
  }
     }
     Thread.yield();
 }
    }

    private class AppInitThread extends Thread
    {
 public void run()
 {
     for( int i = 0; i < 20; i++ ) {
  message( "hello " + i );
  try {
      Thread.sleep( 1000 );
  } catch( Exception x ) {
  }
     }
 }
    }

    //statics ------------------------------------------------------------------

    static public final void main(String[] args)
    {

        new AccessTest().enterEventDispatcher();
    }


    //constructors -------------------------------------------------------------
    public AccessTest() {
        SampleCreatorScreen screen = new SampleCreatorScreen();
 _mainScreen = screen;

        pushScreen(screen);

    }

    public void activate()
    {
 if( !_hasActivated ) {
     AppInitThread t = new AppInitThread();
     t.start();
     _hasActivated = true;
 }
    }

  public void message(String msg)
    {
        if( msg != null ) {
     _mainScreen.message( msg );
        } else {
            Dialog.alert( "Error: message lost or null" );
        }
    }
}

Developer
pfbertrand
Posts: 32
Registered: ‎11-21-2008
My Device: Not Specified

Re: Auto scroll down as text comes into RichTextField

To clarify, my question is, how do I modify the RichTextField and have the display scroll down at the same time so that the last message is visible as it is added?
BlackBerry Development Advisor
MSohm
Posts: 14,752
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Auto scroll down as text comes into RichTextField

The field created in this sample may provide you with what you are looking for.

 

Pimp My Object: Creating a TextBox Field

 http://na.blackberry.com/eng/devjournals/resources/journals/jul_2005/creating_textbox_field.jsp

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Auto scroll down as text comes into RichTextField

Hi all,

 

        can blackberry APIs support views??? ( which are present in the APIs of iphone and Android) what is the alternative for those views in blackberry? i need to place a view over another view. how can i perform it in blackberry.

 

 

Thanks and Regards,

PraveenGoparaju 

Thanks and Regards,
PraveenGoparaju.