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
ankur_siwach
Posts: 145
Registered: ‎09-28-2012
My Device: Blackberry Developer
Accepted Solution

Scroll a label field text

Hello,

 

I have a label field which is added inside the VerticalFieldManager i have fixed the length and height of that label field in how much area i want to display the text,

now i want that my text scroll inside that labelfield.

 

here is my code please help...

 

VerticalFieldManager vf = new VerticalFieldManager(Manager.VERTICAL_SCROLL );

LabelField story=new LabelField(story_data.elementAt(0).toString(),FIELD_HCENTER | FOCUSABLE ){
public void paint(net.rim.device.api.ui.Graphics graphics) {
graphics.setColor(Color.BLACK);
graphics.setFont(net.rim.device.api.ui.Font.getDefault().derive(net.rim.device.api.ui.Font.BOLD, 10));
super.paint(graphics);
}
protected void layout(int width, int height) {
super.layout(width, height);
this.setExtent((MyApp.width)-30, 300);
}
};
story.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
story.setMargin(10, 15, 15, 15);
story.setPadding(5, 5, 5, 5);
story.setFont(Resize.getFirstFont());
vf.add(story);
VerticalFieldManager temp=new VerticalFieldManager();
temp.add(vf);
add(temp);

 

Thanx

 


----------------------------------------------------------
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.
Please use plain text.
Developer
peter_strange
Posts: 19,607
Registered: ‎07-14-2008
My Device: Not Specified

Re: Scroll a label field text

Have you see this?

http://supportforums.blackberry.com/t5/Java-Development/Edit-Field-single-line-and-horizontal-scroll...

 

I appreciate it is an EditField, but a non editable EditField is pretty much a LabelField and/or I suspect you can review and use the same techniques for a LabelField.  So I suspect the code and ideas will be useful to you. 

 

There are some oddities in your code:

 

1) "graphics.setFont(net.rim.device.api.ui.Font.getDefault().derive(net.rim.device.api.ui.Font.BOLD, 10));"

You care creating this font every time you go through paint.  Why not do it once and set that Font for the Field.  In fact you do set a Font for the Field already:

story.setFont(Resize.getFirstFont());

 

2) "this.setExtent((MyApp.width)-30, 300);"

Won't the height be a function of the font size?  And why 300 for the width.  Given that you have already asked the LabelField to lay itself out inside the rectangle given by width and height, you suddenly changing this size seems likely to cause problems.  It would be better to pass the limit into the call to super.layout.  But make sure that you always pass in the minimum of the value you want, and the size you have been given. 

 

3) "VerticalFieldManager temp=new VerticalFieldManager();"

I don't understand what this VFM is doing - it doesn't seem to providing any useful service. 

Please use plain text.
Developer
ankur_siwach
Posts: 145
Registered: ‎09-28-2012
My Device: Blackberry Developer

Re: Scroll a label field text

thanx peter.. my problem is solved... here is my updated code... VerticalFieldManager vf = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR | Manager.VERTICAL_SCROLL_MASK | Manager.VERTICAL_SCROLLBAR_MASK){ protected void sublayout(int width, int height) { super.sublayout(width, height); this.setExtent((MyApp.width)-20, (MyApp.height)-(MyApp.height)/4); } }; LabelField story=new LabelField(story_data.elementAt(0).toString(),FIELD_HCENTER ){ public void paint(net.rim.device.api.ui.Graphics graphics) { graphics.setColor(Color.BLACK); super.paint(graphics); } }; story.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE)); story.setMargin(10, 15, 15, 15); story.setPadding(5, 5, 5, 5); story.setFont(Resize.getSecondFont()); vf.add(story); add(vf);

----------------------------------------------------------
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.
Please use plain text.
Developer
peter_strange
Posts: 19,607
Registered: ‎07-14-2008
My Device: Not Specified

Re: Scroll a label field text

Ah sorry, I misunderstood and thought you wanted a single line scrolling. 

 

In fact this is a better reference for you.

http://supportforums.blackberry.com/t5/Java-Development/TextBoxField-revisited/ta-p/548410

 

I suspect your sublayout may cause you rpbolems.  I would change it to this:

super.sublayout(MyApp.width-20, height);

so that the Field knows it has to layout the text inside the width that you are giving it to display. 

 

Please use plain text.