blackberry - Labelfield text not wrapping -
the below class extends labelfield when display large amount text does'nt wrap new line. text trails across screen. when use labelfield text wraps. need update paint method?
thanks
import net.rim.device.api.ui.drawstyle; import net.rim.device.api.ui.font; import net.rim.device.api.ui.graphics; import net.rim.device.api.ui.component.labelfield; public class fclabelfield extends labelfield { private object text; private font font; private int colour; private long style; public fclabelfield(object text, long style , font font, int colour) { super(text, style); this.text = text; this.font = font; this.colour = colour; } protected void paint(graphics graphics) { graphics.setcolor(colour); graphics.setfont(font); graphics.drawtext(text.tostring(), 0, 0, drawstyle.hcenter, getcontentwidth()); } }
this works -
import net.rim.device.api.ui.drawstyle; import net.rim.device.api.ui.font; import net.rim.device.api.ui.graphics; import net.rim.device.api.ui.component.labelfield; public class fclabelfield extends labelfield { private object text; private font font; private int colour; private long style; public fclabelfield(object text, long style , font font, int colour) { super(text, style); this.text = text; this.colour = colour; super.setfont(font); } protected void paint(graphics graphics) { graphics.setcolor(this.colour); super.paint(graphics); } }
in first version overriding paint
method , not calling superclass' paint
method. in second, are, allows code in base class paint text.
if don't want call superclass' paint
method, have change paint method calculate extent of string you're going draw , split @ appropriate points, making multiple calls drawtext
draw each fragment separately @ different y location. that's paint
method in labelfield
default, need emulate it.
when call superclass paint
method, reason setting font on superclass works , setting font in paint
method doesn't because superclass' paint
method calling setfont
on graphics
object, overwriting did in paint
method.
Comments
Post a Comment