Custom text field

I want to implement a custom text field that displays its label on the leading edge of a line and its part editable on the TRAILING edge of the same way like a ChoiceField. Is there a documentation available to achieve this (maybe it's to say-sample code)? Or even if I could see the source code for ChoiceField. I develop for a Blackberry Pearl 8110 with 4.3.

I ended up solve this using managers of horizontal inside vertical management. I have to use a label field for the edit field that accompanies it. When lines are added, I followed is the width of the new label. Then in sublayout to align the edit fields according to the maximum width more stored a Variant. Could not align all the way to the right.

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.text.*;

public class MyLayoutManager extends VerticalFieldManager {
    protected int maxw;
    protected Font font;
    protected int font_height;
    private int size;

    public MyLayoutManager() {
        super(Field.USE_ALL_WIDTH);
        this.maxw = 0;
        this.font = Font.getDefault().derive(Font.PLAIN, 12);
        this.font_height = this.font.getHeight();
        this.size = 0;
    }

    public void addLine(String label, int initial) {
        MyEditField mef = new MyEditField(label, initial);
        int label_width = this.font.getAdvance(label);
        this.maxw = Math.max(label_width, this.maxw);
        this.add(mef);
        this.size++;
    }

    public int getPreferredHeight() {
        return this.size * this.font_height;
    }

    public int getPreferredWidth() {
        return 240;
    }

    protected void sublayout(int maxwidth, int maxheight) {
        int y = 0;
        for (int i = 0; i < this.size; i++) {
            Field f = this.getField(i);
            this.setPositionChild(f, 0, y);
            this.layoutChild(f, 240, this.getPreferredHeight());
            y += this.font_height;
        }
        this.setExtent(240, this.getPreferredHeight());
    }

    protected class MyEditField extends HorizontalFieldManager {
        private LabelField the_label;
        private JunkField the_value;

        public MyEditField(String label, int initial) {
            super(Field.USE_ALL_WIDTH);
            this.the_label = new LabelField(label);
            this.the_label.setFont(font);
            this.the_value = new JunkField(initial + "");
            this.the_value.setFont(font);
            this.add(this.the_label);
            this.add(this.the_value);
        }

        public int getPreferredHeight() {
            return font_height;
        }

        public int getPreferredWidth() {
            return 240;
        }

        protected void sublayout(int maxwidth, int maxheight) {
            Field f = this.getField(0);
            this.setPositionChild(f, 0, 0);
            this.layoutChild(f, maxwidth, maxheight);
            f = this.getField(1);
            this.setPositionChild(f, maxw + 20, 0);
            this.layoutChild(f, maxwidth, maxheight);
            this.setExtent(maxwidth, font_height);
        }

        private class JunkField extends EditField {
            private boolean firstFocus;

            public JunkField(String deflt) {
                super(Field.EDITABLE | Field.FOCUSABLE);
                this.setText(deflt);
                this.setFilter(new NumericTextFilter(TextFilter.NUMERIC));
                this.firstFocus = false;
            }

            protected void onFocus(int direction) {
                this.firstFocus = true;
            }

            protected boolean keyChar(char key, int status, int time) {
                if (this.firstFocus) {
                    this.setText("");
                    this.firstFocus = false;
                }
                return super.keyChar(key, status, time);
            }
        }

    }
}

Tags: BlackBerry Developers

Similar Questions

  • Slider custom text field (Cap) does not appear

    All;

    I created a custom text field based on the standard text field, changes work fine (really just a custom height and width and a border).  The problem is the method of painting which seems to remove the cap of the field when it gets the focus.  To be clear the carret never shown at all.

    public class CustomText extends TextField //cutom text field width
    {
        //Custom Height and Width in Pixels
        final static int textwidth=125;
        final static int textheight=25;
    
         CustomText()
         {
         super(); // Call the default constructor    
    
         //Border for text fields
         XYEdges padding = new XYEdges(5, 5, 5, 5); //space between box and border
         Border theborder = BorderFactory.createSimpleBorder(padding, Border.STYLE_SOLID);
    
         //Assign the border to the object
         this.setBorder(theborder);
         }
    
         public void onFocus( int direction )
         {
            super.onFocus( direction ); //invoke parent procedure
            invalidate(); //mark for redraw
         }
    
         public void onUnfocus()
         {
        super.onUnfocus(); //invoke parent procedure
        invalidate(); //mark for redraw
         }
    
         //Override the layout with the custom Width and Height
         protected void layout(int width, int height)
         {
            super.layout(textwidth,textheight);
            setExtent(textwidth,textheight);
    
         }      
    
        //Override the display message such that no message is displayed when the field is full
        protected void displayFieldFullMessage()
        {
        }
    
        //Override the default paint method to call the super class constructor and then assign the border
        protected void paint(Graphics graphics)
        {
           // int prevColor = graphics.getColor(); //Save Previous Color
            graphics.setBackgroundColor(Color.LIGHTGRAY); // Set to Gray
            graphics.clear(); // Clear for redraw
            super.paint(graphics); //Force Redraw of Object
          //  graphics.setColor(prevColor); //restore for cursor paint
    
        }
    
    };
    

    In the paint in the first and last method lines that are commented out were a soloution that I tried after reading on this subject.  Something along the lines of the restoration of the default color, but unfortunately without success.   Any ideas would be more useful

    Thank you!

    Quick thoughts:

    (a) to remove the requirement to substitute paint by setting the background a Color.LIGHTGRAY using the base class

    (b) you put on the field by using this:

    Super.Layout (TextWidth, TextHeight);

    If you then do the following:

    setExtent (textwidth, textheight);

    you are likely to confuse the field.  If you still want to use the entire height and use the full width and then try to deal with it in the Style, that is, replace this:

    Super(); Call the default constructor

    with this

    Super(TextField.USE_ALL_HEIGHT |) TextField.USE_ALL_WIDTH); Call the default constructor

    (c) why you override onFocus and onUnfocus?  I would like to delete these if you do not have anything specific to these methods.

    Make these changes, and you'll have a more simple TextField.  See if these changes will solve the problem of the caret too.

  • Format custom text field only when the field is filled

    I have created a form that I need to have the format of a text field "model:"& value of text field, then when it is empty so it is just empty.»

    I put event.value = "template:" + event.value; "." in the format custom properties of the text field it set to format correctly, but if it had not entered in this field he said always model: so what should I do for it to be only occur when there is something entered in the field.

    Change to:

    If (event.value) event.value = "template:"+ event.value; ".

  • Error when creating custom text field

    HI Guyz,

    I am getting below error while creating a new custom UDF text field. All the world is facing this problem earlier?

    "Houston-COLUMN_UNAVAILABLE: no additional custom attributes of this type cannot be created"

    Swati - PÉAN

    The problem is finally solved.

    Yes, there are several udf to IOM. However, it stores the details in a table of the adf. Cleaning of the custom fields were created.

    TRUNCATE TABLE ADF_EXTENSION_COLUMN_USAGE;

    DELETE ADF_EXTENSIBLE_TABLE_USAGE;

    COMMIT;

    -Swati Pandey

  • Custom text fields

    How to make a text field that starts with "Dear," pulls a name to a different field, then ends with a comma?

    If the name of the other field is 'Name', say, you can use this code as the custom code of the field:

    var name = this.getField("Name").value;

    If (name) event.value = 'Expensive' + name + by ', ';

    else event.value = "";

  • refer to his car in custom text field calc

    I have a custom for a text field calculation, but I would like to know if it is possible to set the field itself as a variable without having to refer to the field name.  EITHER this.getField ("name") works, but I want to use this same script a number other text fields and do not want to customize each one.

    To get a reference to the field to which the script is attached, the field object is the value of event.target, so the code could be simplified as follows:

    // Custom Calculate script
    event.target.readonly = getField("Set 1").value === "Off" ? true : false;
    

    I changed to the analysis with a value of "Off", because the script didn't need to know what is the value of exports from the box. A deselected checkbox will have a value of "Off". This makes the script more generic.

  • Please help me with the custom text field FormCalc

    There is someone online has done a very good thing for me - they helped me create a text field that would be of type 'this document has been printed on _' and include some day the pdf was printed on the employer's intranet site.

    I had a shortcut in my favorites and would click on it and place it on each new document that I needed on.

    Because the computer I was using suddenly fell down, can't get the details of how to set it up again. I have a pdf form that includes the box, but when I open it in LiveCycle, it's just empty.

    That's what I saved:

    < field h = mm "8,4935" name = "PrintedOn" w = "141,0398 mm" x = "-0,0001 mm" y = "0 mm" xmlns ="http://www.xfa.org/schema/xfa-template/2.5/" > ""
    < ui >
    < textEdit >
    < border hand = 'right' presence = "hidden" >
    <? templateDesigner styleId aped0? > < / border >
    < margin / >
    < / textEdit >
    < /UI >
    < police size = cast "18pt" = "Tahoma" weight = "bold" >
    < filling >
    < color value = "221,221,221" / >
    < / filling >
    < / make >
    < para hAlign = "center" vAlign = "middle" / >
    < link match = "none" / >
    < activity = "prePrint" ref = "$host" >
    < script >$ .rawValue = concat ("this document has been printed on:", num2date (date (), DateFmt (1))); < /script >
    < / event >
    < / field >

    I don't remember what to do to get this working.

    I use this text box "print on" ALL the time, and I need to know what to do to get back to work quickly.

    If there is someone who could help me, I could also send you a sample of a form which includes it - so you can see exactly what I mean.

    If someone could remember how to program this kind of thing in once again and save it in LiveCycle, then explain how I can put it on another computer so I'd really, REALLY appreciate it.

    ~ Chris

    PS - this one as I had put in place only prints print message per day on the first page. If she could somehow print on EACH page of the PDF file without me having to click and add it to each page individually, it would be better... but let's first!

    Hello

    The script is here. If you place a new textfield in the Master Page and put the following script in the event of pre-publication of the field:

    $ = concat("This document was printed on: ", num2date(date(), DateFmt(1)))
    

    The language is FormCalc.

    Please note that you don't need to go to the XML Source for this. Simply select the textfield object and open the Script Editor (in the Windows menu). Drag the bottom of the editor bar so that you can see a few lines, and then set the FormCalc language.

    Should work,

    Niall

  • CUSTOM TEXT FIELD PROBLEM

    public class CustText extends TextField{
        private String _text;
        private FontFamily _fontFamily1;
        private int _size, _color;
        private Font _headFont = null;
    
        public CustText(String _text, int _size,int _color, long _property)
        {
            super(_property);
            this._text = _text;
            this._size = _size;
            this._color = _color;
        }
    
        protected void paint(Graphics g)
        {
            try{
                _fontFamily1 = FontFamily.forName("aerial");
            } catch(ClassNotFoundException e) {
                    _fontFamily1 = Font.getDefault().getFontFamily();
            }
            _headFont = _fontFamily1.getFont(Font.PLAIN,_size);
                g.setColor(_color);
            g.setFont(_headFont);
            g.drawText(_text,0, 0);
        }
    }
    

    I use the above code to customTextfield, the problem here is, when it is used to display long text that does not move to the next line, only the first line is painted, the rest of the lines are missing

    Graphics.drawText draws text on a single line.  This example allows input of multi line.

    http://supportforums.BlackBerry.com/T5/Java-development/create-a-custom-field-using-attributes-of-OT...

  • focus with custom text field problem

    Hello

    I am new to BB dev., trying to write a small program with two CustomTextFields, but faceing the problem, then try to verify that CustomTextField is selected (the focus).

    CustomTextField (NumericTextField)

    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.component.EditField;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.system.Characters;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Font;
    
    public class NumericTextField extends Manager
    {
    
        private final static int DEFAULT_LEFT_MARGIN = 10;
        private final static int DEFAULT_RIGHT_MARGIN = 10;
        private final static int DEFAULT_TOP_MARGIN = 5;
        private final static int DEFAULT_BOTTOM_MARGIN = 5;
    
        private final static int DEFAULT_LEFT_PADDING = 10;
        private final static int DEFAULT_RIGHT_PADDING = 10;
        private final static int DEFAULT_TOP_PADDING = 5;
        private final static int DEFAULT_BOTTOM_PADDING = 5;
    
        private int topMargin = DEFAULT_TOP_MARGIN;
        private int bottomMargin = DEFAULT_BOTTOM_MARGIN;
        private int leftMargin = DEFAULT_LEFT_MARGIN;
        private int rightMargin = DEFAULT_RIGHT_MARGIN;
    
        private int topPadding = DEFAULT_TOP_PADDING;
        private int bottomPadding = DEFAULT_BOTTOM_PADDING;
        private int leftPadding = DEFAULT_LEFT_PADDING;
        private int rightPadding = DEFAULT_RIGHT_PADDING;
    
        private int totalHorizontalEmptySpace = leftMargin + leftPadding + rightPadding + rightMargin;
        private int totalVerticalEmptySpace = topMargin + topPadding + bottomPadding + bottomMargin;
    
        private int minHeight = getFont().getHeight() + totalVerticalEmptySpace;
        private int width = Display.getWidth();
        private int height = minHeight;
    
        private EditField editField;
    
        public NumericTextField()
        {
            super(0);
    
            editField = new EditField(EditField.FILTER_REAL_NUMERIC);
            add(editField);
        }    
    
        protected void sublayout(int width, int height)
        {
            Field field = getField(0);
            layoutChild(field, this.width - totalHorizontalEmptySpace, this.height - totalVerticalEmptySpace);
            setPositionChild(field, leftMargin+leftPadding, topMargin+topPadding);
            setExtent(this.width, this.height);
        }
    
        public void setTopMargin(int topMargin)
        {
            this.topMargin = topMargin;
        }
    
        public void setBottomMargin(int bottomMargin)
        {
            this.bottomMargin = bottomMargin;
        }    
    
        protected void paint(Graphics graphics)
        {
            graphics.drawRoundRect(leftMargin, topMargin, width - (leftMargin+rightMargin), height - (topMargin+bottomMargin), 5, 5);
    
            boolean longText = false;
            EditField ef = (EditField)getField(0);
            String entireText = ef.getText();
    
            String textToDraw = "";
            Font font = getFont();
            int availableWidth = width - totalHorizontalEmptySpace;
            if (font.getAdvance(entireText) <= availableWidth)
            {
                textToDraw = entireText;
            }
            else
            {
                int endIndex = entireText.length();
                for (int beginIndex = 1; beginIndex < endIndex; beginIndex++)
                {
                    textToDraw = entireText.substring(beginIndex);
                    if (font.getAdvance(textToDraw) <= availableWidth)
                    {
                        longText = true;
                        break;
                    }
                }
            }
    
            if (longText == true)
            {
                ef.setText(textToDraw);
                super.paint(graphics);
                ef.setText(entireText);
            }
            else
            {
                super.paint(graphics);
            }
        }
    
        public int getPreferredWidth()
        {
            return width;
        }
    
        public int getPreferredHeight()
        {
            return height;
        }
    
        protected boolean keyChar(char ch, int status, int time)
        {
            if (ch == Characters.ENTER)
            {
                return true;
            }
            else
            {
                return super.keyChar(ch, status, time);
            }
        }
    
        public String getText()
        {
            return ((EditField)getField(0)).getText();
        }
    
        public void setText(final String text)
        {
            ((EditField)getField(0)).setText(text);
        }
    }
    

    and in my screen content trying to check:

    NumericTextField focusImput() {
        NumericTextField focusField;
        if (_fieldFrom.isFocus()) {
            focusField = _fieldtFrom;
        }
        else {
            focusField = _fieldTo;
        }
        return focusField;
    }
    

    but it always returns me _fieldTo...

    NumericTextField definition:

    _fieldFrom = new NumericTextField();
    _fieldFrom.setChangeListener(this);
    manager.add(_fieldFrom);
    
    _fieldTo = new NumericTextField();
    _fieldTo.setChangeListener(this);
    manager.add(_fieldTo);
    

    Maybe someone to guide me how to correctly focus feature?

    Thanks in advance.

    Then you need two slightly customized EditFields - their main customization would be limiting their width, as well as making them focusable/unfocusable. So, something like this should work:

    public class NumericTextField extends EditField {
      // override the constructors used in your code, adding FILTER_REAL_NUMERIC
      // ...
      private int maxWidth = Integer.MAX_VALUE >> 1;
      private boolean focusable = true;
    
      protected void layout(int width, int height) {
        super.layout(Math.min(maxWidth, width), height);
      }
    
      public void setMaxWidth(int width) {
        maxWidth = width;
        updateLayout();
      }
    
      public boolean isFocusable() {
        return (isStyle(FOCUSABLE) & focusable);
      }
    
      public void setFocusable(boolean on) {
        focusable = on;
      }
    }
    

    If you want to place the fields, use setMargin - he is documented in OS 6.0 but works since OS 4.2.

    Use setMaxWidth to, well, set desired maximum width (otherwise EditField tenorman to the top of the entire available width). Use the setFocusable to toggle the field. In addition, you can play with the Visual States for the field you turn, but it's an exersize for another day. First of all make sure that it works and you know how to use it.

  • Getpreferredwidth and getpreferredheight custom text field

    I have a customtextfield that I have to get the width of textfields, I tried getpreferredwidth() substitution but I'm stacoverflowmethod, I can understand the reason for the error but I tried getwidth() substitution I get 10 as standard response. I am not able to understand the error.

    public class CustTextField extends RichTextField{
    
        private String _text;
        private FontFamily _fontFamily1;
        private int _size, _color;
        private Font _headFont = null;
    
        public CustTextField(String _text, int _size,int _color, long _property)
        {
            super(_text, _property);
            FontFamily _fontFamily1;
            this._color = _color;
            try{
                _fontFamily1 = FontFamily.forName("aerial");
            } catch(ClassNotFoundException e) {
                    _fontFamily1 = Font.getDefault().getFontFamily();
            }
             _headFont = _fontFamily1.getFont(Font.PLAIN,_size);
             super.setFont(_headFont);
        }
    
        public int getPreferredWidth() {
            // TODO Auto-generated method stub
            return getPreferredWidth();
        }
    
        protected void paint(net.rim.device.api.ui.Graphics g) {
            g.setColor(_color);
            super.paint(g);
        }
    }
    

    A Y

    You can use font.getAdvance

  • Rich text field, scroll problems

    Hello world

    I currently have a problem with the rich text fields.  I have a selected rich when custom text field (onFocus), it colors the blue text when not selected (onUnfocus), the text is white.

    I have Setup several of my RichTextFields in a VerticalFieldManager so they can be scrolled as a list.

    Now scrolling works on the following simulators:

    Bold 9000 4.6.0.266

    Curve 8520 4.6.1.272

    But no scrolling does work on this Simulator:

    Bold 9700 5.0.442

    What Miss me?  I know the o/s changed, but if it should not be backward compatible?

    I use Blackberry JDE component Package 4.2.1

    Any help would be greatly appreciated.

    I found the problem.  The super I was calling was super (text, Field.FOCUSABLE), this caused the 9700 Simulator not to focus the richtextfields.

    The Builder suitable for call is super (Field.FOCUSABLE), and that fixed the issue.

    Now, I have another problem.  Suddenly, I added a few images, the background (they are all less than 300 KB) tested on simulators of 9000 and 8520, it worked.

    When I test it on the 9700, it says net.rim.device.api.system.Application not found

    Hint anyone?

  • How can I use a number of text field custom times?

    Hello

    is it possible to create a field of custom text so that I can reuse a class several times.

    If possible, then pls provide me an example.

    thankx.

    Similarly...

    [] customTextField = new customTextField myArray [2];

    myArray [0] = new customTextField();

    ...

    And you can do something like:

    MyArray [] TextField = new TextField [] {new TextField(), new customTextField};

  • Custom edit field - not drawing while typing of the text

    I created a custom edit field (code below), but there is no slider or text drawn while typing.

    The text appears if you click another field on the screen, but not while typing. I guess it has something to do with my method of painting, but I don't know?

    Tips for making more effective methos painting would be a bonus!

    Thank you!

    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.FontFamily;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.component.EditField;
    
    public class CustomTextField2 extends EditField {
    
        private int fieldWidth;
        private int fieldHeight;
        private int button_colour = 0xF9F9F9;
        private int text_colour = 0x666666;
        private int border_color = 0xCCCCCC;
        private Graphics graphics = null;
        public CustomTextField2(long arg0) {
            super(arg0);
            fieldWidth = Display.getWidth()-100;
            //int off = 8;
            FontFamily fFam = null;
    
            try {
                fFam = FontFamily.forName("SomeFontHere");
            }
            catch (ClassNotFoundException e) {
                e.printStackTrace();
            }  
    
            Font font = fFam.getFont(Font.PLAIN, 20);
    
            Font defaultFont = font;
            int off = 8;
            fieldHeight = defaultFont.getHeight() + off + 10;
            this.setPadding(5, 20, 5, 20);  }
    
        protected void paint(Graphics graphics) {
    
            graphics.setColor(button_colour);
            graphics.fillRect(0, 0, fieldWidth, fieldHeight);
            graphics.setColor(border_color);
            graphics.drawRect(0, 0, fieldWidth, fieldHeight);
            graphics.setColor(text_colour);
            graphics.drawText(this.getText(),20,10/2);               super.paint(this.graphics);
        }
    
        protected void onFocus(int direction) {
    
            button_colour = 0xF9F9F9;
            text_colour = 0x666666;
            border_color = 0x3598CC;
            this.invalidate();
        }
    
        protected void onUnfocus() {
    
            button_colour = 0xF9F9F9;
            text_colour = 0x666666;
            border_color = 0xCCCCCC;
            this.invalidate();
        }
    
        protected void drawFocus(Graphics graphics, boolean on) {
    
              super.drawFocus(graphics, on);
        }
    
        protected void fieldChangeNotify(int context)
        {
            try {
    
            this.getChangeListener().fieldChanged(this, context);
    
            }
            catch (Exception e){
    
            }
        }
    
        public int getPreferredHeight() {
    
            return fieldHeight;
        }
    
        public int getPreferredWidth() {
    
            return fieldWidth;
        }
    
        protected void layout(int arg0, int arg1) {
    
            setExtent(getPreferredWidth(), getPreferredHeight());
        }
    }
    

    I just posted a code in another thread - he does most, if not all, of what you want. Take a look:

    Custom elegant EditField (textbox)

  • How to make a custom text in eSign field?

    I'm doing my custom field in this format: 1234-56-7. I can't figure out how to make this happen by using a custom expression. Any advice or tips? I use a text field with custom regular expression.

    Thank you!

    Hello Lisaw31172184,

    I recommend adding three separate text fields and provide the Maximum character limit in each of them. Here is the reference for help:

    https://helpx.Adobe.com/document-cloud/KB/EchoSign-credit-card-fields.html

    Let me know if you need more information.

    -Usman

  • Custom Custom Format AND Date text field label

    I have created a form where I wanted each form field to have a label so that the user knows what to connect, BUT when I arrived at this day it became clear that I can only do one or the other, enter a name or select a date format, because they are both under the same category selection and you can choose only one. I found a previous discussion and was able to use the following code to label all the text fields and he also mentioned that an additional coding would be required to customize the date:

    Custom format for text field script

    If (! event.value) {}

    Event.Value = "enter meeting requested Date."

    Event.Target.Display = display.noPrint;

    } else {}

    Event.Target.Display = display.visible;

    }

    Now my problem is that in order to label the tabled text, I had to do a custom format, so I am unable to choose a custom date format. Instead of getting the error message when the format is wrong there at - it a way to make sure that no mater what type of date is connected, it is automatically reformatted to (mmmm dd, yyyy)?

    I don't know am new to the form of coding features and indeed if there is another way to lock it I would appreciate the help.

    Yes, it is possible... Basically you would use something like this as the custom for the field validation script:

    Event.RC = true;

    If {(event.value)

    var d = util.scand ("mm/dd/yyyy", event.value);

    If (d == null) {}

    App.Alert ("Invalid value.");

    Event.RC = false;

    } else {}

    Event.Value = util.printd ("mmmm dd, yyyy", d);

    Event.Target.Display = display.visible;

    }

    } else {}

    Event.Value = "enter meeting requested Date."

    Event.Target.Display = display.noPrint;

    }

    I have not tested, but I think he should do the trick.

Maybe you are looking for