user interface - How to set cursor position in the middle of CustomEditField? -


i have created custom edit field rounded border. cursor displaying @ top of customeditfield. how change cursor position center of field. need on issue. following code snippet implementation of customeditfield.

public customeditfield() {     this(0);     setmaxsize(15);     setcursorposition(axis_vertical); }  public customeditfield(long style) {     this(new xyedges(20, 10, 20, 10), field.field_hcenter             | field.use_all_width | field.non_spellcheckable             | textfield.no_newline | consume_input | style); }  public customeditfield(string label, string initialvalue) {     this(0);     setlabel(label);     settext(initialvalue); }  public customeditfield(xyedges points, long style) {     super(style);     setpadding(points); }  /**  * paints editfield background specified format values  */ protected void paintbackground(graphics graphics) {     graphics.setcolor(color.white);     graphics.fillroundrect(10, getpaddingtop(), getwidth() - 10,             getheight() - getpaddingbottom(), 20, 20);     graphics.setcolor(0x686868);     graphics.drawroundrect(10, getpaddingtop(), getwidth() - 10,             getheight() - getpaddingbottom(), 20, 20);     graphics.setcolor(color.black); } 

first, there's few concepts make sure you're clear on. field, there margin, padding, , border. here description of represent ... linked question android, far know, android , blackberry use concepts in same way.

if want rounded rectangle border, when you're drawing it, don't start coming in amount of padding. padding goes inside border. so, should draw rectangles @ (x,y) == (0,0). if want provide space outside of border, buffer between other fields, use margin that. field objects have setmargin() call looks setpadding().

secondly, method setcursorposition() not centering cursor's layout in space. it's setting character in editfield cursor should next to. not want problem.

also, above code isn't plotting rectangles symmetrically. remember when have padding on both sides, have subtract top and bottom pad remaining height, or subtract left and right remaining width.

anyway, depending on how want customeditfield padded, may need change little. but, following @ least give edit field cursor vertically centered.

public class customeditfield extends basiceditfield {    public customeditfield () {       this(0);       setmaxsize(15);       //setcursorposition(axis_vertical);     }     public customeditfield (long style) {       this(new xyedges(20, 10, 20, 10), field.field_hcenter | field.use_all_width | field.non_spellcheckable             | textfield.no_newline | consume_input | style);    }     public customeditfield (string label, string initialvalue) {       this(0);       setlabel(label);       settext(initialvalue);    }     public customeditfield (xyedges points, long style) {       super(style);       setpadding(points);    }     /**     * paints editfield background specified format values     */    protected void paintbackground(graphics graphics) {       graphics.setcolor(color.white);       graphics.fillroundrect(0, 0, getwidth(), getheight(), 20, 20);       graphics.setcolor(0x686868);       graphics.drawroundrect(0, 0, getwidth(), getheight(), 20, 20);       graphics.setcolor(color.black);    } } 

note give 20 pixels of space above text, before rounded rectangle (if use default constructor). looks lot. maybe that's not want. might decide take padding on 4 sides down 10 pixels, , use setmargin() on field provide space outside border. you'll have play around it.

by way, way attack problem, use lot, wrap editfield inside manager, verticalfieldmanager. if that, , add() editfield verticalfieldmanager, style flags = field.field_vcenter, should accomplish goal. in case, don't think that's necessary.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -