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
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900
Accepted Solution

Why doesn't my VFM scroll

I created a screen in my app and i need it to scroll otherwise I can't fit everything on the screen, however I can't get anything to scroll unless I create some kind of list. I created  simple test to illustrate what I ma trying to do, you can see below all I do is cretae 50 labels which will exceed the screen length (Bold 9900) and I expect it would show a scroll bar and/or let me scroll down, but i have no scroll bar and cannot scroll at all.

 

 

import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.*;


public final class TestScreen extends MainScreen
{

public TestScreen()
{
super(FullScreen.NO_VERTICAL_SCROLL | FullScreen.VERTICAL_SCROLLBAR);

final VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_HEIGHT | VERTICAL_SCROLL | VERTICAL_SCROLLBAR);

for (int i=0; i<50;i++){
add(new RichTextField("Line " + String.valueOf(i)));
}
add(vfm);

}
}

Please use plain text.
Developer
simon_hain
Posts: 16,096
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Why doesn't my VFM scroll

you add your fields to the screen, not to the vfm.

if you add so many fields you should consider addAll, it has a much better performance.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Why doesn't my VFM scroll

[ Edited ]

I notice what ppears to be some inconsistencies in the style flags you have used:

 

1) super(FullScreen.NO_VERTICAL_SCROLL | FullScreen.VERTICAL_SCROLLBAR);

 

You are extending MainScreen, so you should use MainScreen style flags here.  Also If you have told the Screen, that there is no vertical scroll, why would it need to have a scroll bar?

 

I would remove these completely.

 

2) final VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_HEIGHT | VERTICAL_SCROLL | VERTICAL_SCROLLBAR);

 

Use all height  is telling the Manager to use the whoel screen height.  I don't think you need to do this, so I would remove it.  And as the other are the default actions, then I would remove then as well.

 

 

What I am basically saying is that if you remove all your style indicators, it should work as you require.

 

One final thing though, be aware that Fields must be focusable to facilitate scrolling.  I beleive RichTextFields are focusable by default, so this should not be a problem.  But you might want to try forcing it with:

 

add(new RichTextField("Line " + String.valueOf(i), RichTextField.FOCUSABLE));

 

Hope this helps. 

 

Edit:

 

Just to expand on Simon's points:

1) you could add the Fields directly, but the approach you are taking should work too.

2) in my experience, AddAll has better performance once the screen has been displayed as it reduces the interaction with displayed screen.  In this case, when the screen is just being constructed, it should no impact. 

Please use plain text.
Developer
alishaik786
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: Why doesn't my VFM scroll

[ Edited ]

Try like this sample code:

 

public class SimpleScreen extends MainScreen
{
	VerticalFieldManager vertical;
	Font font;
	public SimpleScreen() 
	{
		font=Font.getDefault().derive(Font.ITALIC|Font.BOLD, 20);
		createGUI();		
		this.setFont(font);
	}

	private void createGUI()
	{
		vertical=new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
		
		for(int i=0;i<30;i++)
			vertical.add(new LabelField("Label: "+(i+1), Field.FIELD_HCENTER|Field.FOCUSABLE));
		
		add(vertical);
	}	
}
=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.
Please use plain text.
Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: Why doesn't my VFM scroll

Thanks Simon,

 

Yes that was a stupid error in my sample. Also thanks for the tip regarding performance. 

 

My real issue is that if a create a vfm, I can add fields to the screen above the vfm but if I add a tableview to the vfm that works perfectly without the vfm, but if I add it to the vfm I will always get an IllegalState exception 

 

Is there some limitation  that won't allow me to add a tableview to a vfm?

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Why doesn't my VFM scroll

Since that is nothing like the Subject of this Thread, I suggest you mark this Thread as solved, and start a new Thread that actually refects the problem you are reporting.  And I have to wonder why you asked this question in the first place!

Please use plain text.
Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: Why doesn't my VFM scroll

Thanks Peter,

 

I see your point about the flags, I'll take that on board.   Also your point about the performance about addAll seems to be correct, I have no performance difference in this example.

 

To be honest I can't fine anything that tells me what the USE_ALL_HEIGHT does, just trying to get it working, I guess it means to use the maximum scrollable size of the virtual screen. I removed it and now it's working better by only scrolling to the maximum used screen. Much better :smileyhappy: 

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Why doesn't my VFM scroll

The documentation of the style flags is sparse I agree, and in fact in some cases the flags have different effects in different places.  Sorry I can't point you at anything that will help.  Experience does!

 

The contributor to this KB article, that I recommend you review, seems to understand these better than most. 

http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644

 

Please use plain text.