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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -