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
Posts: 26
Registered: ‎11-27-2008
My Device: Not Specified
Accepted Solution

How can I display last field added to manager (on the bottom) and keep scrolling functionality?

[ Edited ]

The issues around scrolling on the blackberry managers is a real headache.

 

I would like to be able to add fields to the bottom of a Manager and have that field displayed on the bottom without taking the focus from another control.

 

I am looking for something similar to how yahoo chat window works, for example. 

 

I have not been able to get the last label field added to the scrollable area to be displayed. 

 

Here is the relavent code I have:

 

 


//adds a labelfield and a nullfield to the display
public void update()
{
UiApplication.getUiApplication().invokeLater( new Runnable()
{
public void run()
{
try
{
scrollingWindow.add(new LabelField("Hello1" + count) );
//add nullfield to facilitate scrolling
NullField nullField = new NullField( NullField.FOCUSABLE );
scrollingWindow.add(nullField);
count++;
}
catch( Exception ex )
{
Dialog.alert( ex.getMessage() );
}
}
});
}


 

 Any Ideas?

 

 

 

 

Message Edited by thebbk on 01-22-2009 11:00 AM
Developer
Posts: 19,616
Registered: ‎07-14-2008
My Device: Not Specified

Re: How can I display last field added to manager (on the bottom) and keep scrolling functionality?

Couple of quick things:

1) You can make your LabelField focusable and save adding the NullFields

new LabelField("Hello1" + count, Field.FOCUSABLE)

2) have you tried finding out which Field has focus, then setting the focus on your new Field, then resetting it back to the one it originally came from?

Developer
Posts: 19,616
Registered: ‎07-14-2008
My Device: Not Specified

Re: How can I display last field added to manager (on the bottom) and keep scrolling functionality?

Just tried replacing:

 

scrollingWindow.add(new LabelField("Hello1" + count) );
//add nullfield to facilitate scrolling
NullField nullField = new NullField( NullField.FOCUSABLE );
scrollingWindow.add(nullField);

 

with:

 

LabelField lab = new LabelField("Hello1" + count, Field.FOCUSABLE);
scrollingWindow.add(lab);
Field focus = scrollingWindow.getScreen().getLeafFieldWithFocus();
lab.setFocus();
focus.setFocus();

 

However I think this needs to NOT do the focus thing when the focus is actually in scrollingWindow.

 

Happy to do some work on this, if this doesn't do it for you.

Developer
Posts: 26
Registered: ‎11-27-2008
My Device: Not Specified

Re: How can I display last field added to manager (on the bottom) and keep scrolling functionality?

Your tip about setting focus back to the editbox was key.

 

I tried doing that with a different hierarchy of managers and screens and it did not work, but it did work in this arrangement of objects. 

 

I changed the fields from labels to RichTextFields. An interesting thing happened when I added enough text to force a line wrap in the RichTextField - only the first line of the RTF appeared at the bottom of the scroll window. So, I once again put the nullfield in play and setfocus to that to get the entire rtf to show up at the bottom. 

 

As popular as this functionality would seem to be, they don't make it very easy to implement here. 

 

Here is what I came up with for the code that adds the fields:

 

 

public void update() { UiApplication.getUiApplication().invokeLater( new Runnable() { public void run() { try { RichTextField labelField = new RichTextField( "Hello, this is a lot of text and I hope it wraps properly" + count ); labelField.setEditable(false); scrollingWindow.add( labelField ); // labelField.setFocus(); //add nullfield to facilitate scrolling NullField nullField = new NullField( NullField.FOCUSABLE ); scrollingWindow.add(nullField); nullField.setFocus(); //now set focus back to edit field myEditField.setFocus(); count++; } catch( Exception ex ) { Dialog.alert( ex.getMessage() ); } } }); }