how to add any field to custom verticalfieldmanager in blackberry? -
my custom verticalfieldmanger
public class custom_topfield extends verticalfieldmanager { private static final int field_height = 70; private labelfield maintitle; private string _text; custom_topfield(int color, string text) { super(manager.no_vertical_scroll); _text = text; background background = backgroundfactory.createsolidbackground(color); setbackground(background); maintitle = new labelfield(_text, field.field_vcenter | field.field_hcenter); font font = font.getdefault().derive(font.bold, 35); maintitle.setfont(font); add(maintitle); } protected void sublayout(int width, int height) { width = math.min(width, getpreferredwidth()); height = math.min(height, getpreferredheight()); setextent(width, height); } public int getpreferredheight() { return field_height; } public int getpreferredwidth() { return display.getwidth(); } public void paint(graphics graphics) { int rectheight = getpreferredheight(); int rectwidth = getpreferredwidth(); graphics.drawrect(0, 0, rectwidth, rectheight); super.paint(graphics); } } although add(maintitle) did not come out middle of verticalfield.
you can try this:
add flags constructor:
super(manager.no_vertical_scroll | manager.use_all_width); also field:
maintitle = new labelfield(drawstyle.hcenter | field.field_hcenter); this should center horizontally field. can try adding flags center vertically, won't work, because vfm's have issues vertical scrolling. rule is: center horizontally, use verticalfieldmanager, center vertically, use horizontalfieldmanager. how can center in vertical:
horizontalfieldmanager hfm = new horizontalfieldmanager(manager.use_all_height); field tocenter = new <field>(drawstyle.vcenter | field.field_vcenter ); hfm.add(tocenter); you theoretically work out solution combining both approaches, , nesting 1 manager inside other one.
Comments
Post a Comment