EditField setText problem...

Hi everyone out there.

I have a textField in which I enter the text

I added a listener to this text field

hwen I entered text in the text box for each two characters that I need to store the characters and I need to replace the text with ".". (once the dowry for a character)...

is it possible to do...

Here is the code how I did it...

but I know where I am doing wrong...

but I don't get how to solve this...

edit.setChangeListener (new FieldChangeListener() {}

' Public Sub fieldChanged (field field, int context) {}

int length = edit.getTextLength ();
If (length! = 0) {}
String [];

If (length % 2 == 0) {}
int size;
If (length / 2 == 0) {}
size = 1;
} else
size = length / 2;
String = new String [size];
int j = charIndex;
StringBuffer buffer = new StringBuffer();
for (int i = 0; i)< size;="" i++)="">
If (Edit.GetText (j, 2)! = null)
String [i] = edit.getText (d, 2);
for (int y = 0; y)<>
buffer. Append(".");
vertical.deleteAll ();
vertical. Add (new LabelField (string [i]));
vertical. Add (new LabelField (buffer.toString ()));
j = j + 2;

edit.setText (buffer.toString ());    When this line is running the listener calls once again
}

}

} else
vertical.deleteAll ();
}

});

Hey Hey...

I did it with her...

Thank you all...

Tags: BlackBerry Developers

Similar Questions

  • Bimap field + EditField click problem

    Hello

    In my application, I am increasing and decreasing value in an editfield using two buttonfields, everything works fine, but if I click on the changed value in the editifeld picture but menu "Application report" come again by pressing ESC and then only I am able to click on the image.

    Even if I click editfield also 'switch' application menu pop up appears please check the picture of the call and inform me how to limit this menu in the click bimap and editfield

    Note: earlier in the popup 'application Switch, close' options appear in the context menu, but after using the below only switch application code comes

    protected void makeMenu (menu Menu, for example int)
    {
    menu.deleteAll ();
    }

    If you return false, you indicate that you have not consumed the event (and a few other layer will be, so the menu).
    return true instead.

  • Personalized 9800 slider TextBoxfield problem

    Hello

    The custom cursor in textboxfield is not properly get updated. When you enter any text instead of display the cursor at the end of a character, it appears after one or two space character to the last character and when you tap on the evolution of the orientation textboxfield then cursor comes to the appropriate position. That is to say at the end of the last character.

    Even when I delete textboxfield characters, it does not move smoothly. It fluctuates as movement before shows and back, space between the cursor and the last character of the text.

    This behavior I've seen that in the BB Torch 9800 (both device and Simulator). Where as the same code works in other devices such as 9700,9000,9550,8520, all are with OS v5.0.

    Here is my Code of TextBoxField:

    public class TextBoxField extends VerticalFieldManager
    {
        //Define some variables to be used
        //in the class
        private int managerWidth;
        private int managerHeight;
        private EditField editField;
        private String iText;
        private Graphics g1;
        private int myBorderColor;
        private int fillColor;
        private int width;
        private int height;
    
        //Pass in the fixed height and width for our object
        public TextBoxField(int width, int height)//, long style )
        {
            //This call to super will help keep the object in place
            super(Manager.NO_VERTICAL_SCROLL | Manager.USE_ALL_WIDTH);// | Manager.FIELD_HCENTER);
    
            this.width = width;
            this.height = height;
            managerWidth = Display.getWidth() - width;
            managerHeight = height;
    
            //vfm will allow scrolling within the object
            VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.FIELD_VCENTER);
    
            editField = new EditField("", "", EditField.DEFAULT_MAXCHARS, EditField.FOCUSABLE)// | EditField.JUMP_FOCUS_AT_END)
            {
                 public void paint(Graphics g) {
                     //This invalidation will help keep the border clean
                     //while scrolling
                     getManager().invalidate();
                     g.setColor(0xBCBEC0);
                     super.paint(g);
                 }
                 protected void onFocus(int direction) {
                    myBorderColor = 0x469539;
                    TextBoxField.this.invalidate();
                 }
    
                 protected void onUnfocus() {
                    myBorderColor = 0x808285;//0x999999;
                    TextBoxField.this.invalidate();
                }
            };
    
            vfm.add(editField);
            add(vfm);
       }
    
       public void paint(Graphics g)
       {
            managerWidth = Display.getWidth() - 50;
    
            if (managerWidth == 0) {
                managerWidth = width;
    
            }
            if (managerHeight == 0) {
                managerHeight = height;
            }
    
            //Draw a rectangle around out TextBoxField
            //For Border Color
            //int prevColor = g.getColor();
            int prevColor = g.getColor();
            g.setColor(myBorderColor);
            g.drawRoundRect(0, 0, managerWidth, getHeight(), 10, 10);
            g.setColor(prevColor);
    
            //Fills the Rectangle with  color
            g.setColor(Color.WHITE);
            g.fillRect(2, 2, managerWidth-4, getHeight()-4);
    
            super.paint(g);
    
        }
    
        //If this call to sublayout was made by the system then
        //both parameters would be passed with a value of 0.
        //This check and adjustment keeps the fixed properties
        //maintained.
        public void sublayout(int width, int height)
        {
            managerWidth = Display.getWidth() - 50;
           // managerHeight = height;
            if (managerWidth == 0) {
    
                managerWidth = width;
    
            }
            if (managerHeight == 0) {
                managerHeight = height;
            }
            //managerWidth = Display.getWidth() - 50;
            //Force the extent of our manager.
            //This will force the height of the object
            //where the above super.sublayout() call will
            //set the width.
    
            super.sublayout(managerWidth, managerHeight);
            setExtent(managerWidth,managerHeight);
    
        }
    
        //The following two methods allows users of the
        //TextBofField read and set its contents.
        public String getText() {
            return editField.getText();
        }
    
        public void setText(String text) {
            editField.setText(text);
        }
        public void setFont(Font font)
        {
            editField.setFont(font);
        }
    
        public void setFieldChangeListener(FieldChangeListener fl){
            editField.setChangeListener(fl);
        }
    
        public Field getField(){
            return editField;
        }
    
    }
    

    Please help me solve this problem.

    Thank you

    amsiddh.

    Of course, you use the old TextBoxField example, which has a number of problems, the worst being:

            editField = new EditField("", "", EditField.DEFAULT_MAXCHARS, EditField.FOCUSABLE)// | EditField.JUMP_FOCUS_AT_END)
            {
                 public void paint(Graphics g) {
                     //This invalidation will help keep the border clean
                     //while scrolling
                     getManager().invalidate();
                     g.setColor(0xBCBEC0);
                     super.paint(g);
                 }
    

    The highlighted code is causing the flicker.  It just happened is not to affect the older phones too, but it's a wrong code anyway.

    I strongly suggest to read the following article, that you can use as a better starting point:

    TextBoxField revisited

    This article was created to solve the problems with the old. Make sure you read the comments - they have a few ideas on the extension of the feature.

  • Custom elegant EditField (textbox)

    Hello!

    I was wondering if there is a way to create cute user interface components for our applications. I would like to have something like this:

    But the EditField BB is very very ugly. I tried a custom EditField of (http://www.blackberryforums.com/developer-forum/218757-custom-text-edit-filed-vertical-scroll.html)

    But it looks like this:

    It's completely is and ugly, not decent for any application. For cute, we should override the paint method and draw a Bitmap simulating a cute EditField?

    public void paint(Graphics g) {
        super.paint(g);
        g.drawBitmap(0, 0,50, 50, Bitmap.getBitmapResource("profile.png"), 10, 10);
        //g.drawRect(0, 0, getWidth(), getHeight());
    }
    

    If we paint a Bitmap with the height and width fixed, we will see it very small or big if the resolution is changed? For example, in "BOLD" curve with 320 x 240 or 480 x 360.

    Thank you!

    First of all - there is no built-in component like the one you want.

    Second - the article you mentioned has a very harmful code that would avoid you best. I don't know what drunk monkey for the first time getManager () .invalidate () inside the paint, but this piece of code has found its place in more than one article of the BlackBerry UI on the ' Net. Avoid it like the plague.

    Third - you need paint Bitmap image first, then call the super.paint. Otherwise, your bitmap image is painted on the letters!

    Fourth - indeed, the image will be different on different screens. There is a drawTexturedPath method that allows all sorts of affine transformations and the tiles of the original Bitmap. It is quite effective, but could distort Bitmaps. There is also the drawShadedFilledPath, which creates a sort of background gradient. Finally, there are all sorts of classes useful net.rim.device.api.ui.decor package (available since 4.6).

    And finally, the answer to your first question - Yes, there are several ways to create cute user interface components. Here's the complete code for my experience with rounded edge text boxes (it fate multi-line, scrollable vertically)-you can experiment with colors and other things there.

    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FocusChangeListener;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.EditField;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    
    public  class RoundBorderTextBoxField extends Manager implements FocusChangeListener {
        private int managerWidth;
        private int managerHeight;
        private int inactiveBorderColor = Color.BLACK;
        private int activeBorderColor = Color.BLACK;
        private int borderColor = inactiveBorderColor;
        private int backgroundColor = Color.WHITE;
        private int arcWidth;
    
        private VerticalFieldManager vfm = new VerticalScrollManager(VERTICAL_SCROLL | USE_ALL_WIDTH | USE_ALL_HEIGHT);
        private EditField editField;
    
        RoundBorderTextBoxField(int width, int height, long style) {
            super(style | NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL);
            managerWidth = width;
            managerHeight = height;
            long innerStyle = style & (READONLY | FOCUSABLE_MASK); // at least
            if (innerStyle == 0) {
                innerStyle = FOCUSABLE;
            }
            editField = new EditField("", "", EditField.DEFAULT_MAXCHARS, innerStyle);
            editField.setFocusListener(this);
            arcWidth = editField.getFont().getHeight() & 0xFFFFFFFE; // make it even
    
            add(vfm);
            vfm.add(editField);
        }
    
        public void setFont(Font font) {
            super.setFont(font);
            editField.setFont(font);
            arcWidth = editField.getFont().getHeight() & 0xFFFFFFFE;
            updateLayout();
        }
    
        public void setBorderColors(int inactive, int active) {
            inactiveBorderColor = inactive;
            activeBorderColor = active;
            invalidate();
        }
    
        public void setBackgroundColor(int bgColor) {
            backgroundColor = bgColor;
            invalidate();
        }
    
        RoundBorderTextBoxField(int width, int height) {
            this(width, height, 0L);
        }
    
        public String getText() {
            return editField.getText();
        }
    
        public void setText(String newText) {
            editField.setText(newText);
        }
    
        public void append(String addedText) {
            String newText = editField.getText() + addedText;
            editField.setText(newText);
            editField.setCursorPosition(newText.length());
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    vfm.setVerticalScroll(Math.max(0, vfm.getVirtualHeight() - vfm.getVisibleHeight()));
                }
            });
        }
    
        public int getPreferredWidth() {
            return managerWidth;
        }
    
        public int getPreferredHeight() {
            return managerHeight;
        }
    
        protected void sublayout(int w, int h) {
            if (managerWidth == 0) {
                managerWidth = w;
            }
            if (managerHeight == 0) {
                managerHeight = h;
            }
            int actWidth = Math.min(managerWidth, w);
            int actHeight = Math.min(managerHeight, h);
            layoutChild(vfm, actWidth - arcWidth, actHeight - arcWidth); // Leave room for border
            setPositionChild(vfm, arcWidth / 2, arcWidth / 2);  // again, careful not to stomp over the border
            setExtent(actWidth, actHeight);
        }
    
        protected void paint(Graphics g) {
            int prevColor = g.getColor();
            int myWidth = getWidth();
            int myHeight = getHeight();
            g.setColor(backgroundColor);
            g.fillRoundRect(0, 0, myWidth, myHeight, arcWidth, arcWidth);
            g.setColor(borderColor);
            boolean aaLines = g.isDrawingStyleSet(Graphics.DRAWSTYLE_AAPOLYGONS);
            g.setDrawingStyle(Graphics.DRAWSTYLE_AAPOLYGONS, true);
            g.drawRoundRect(0, 0, myWidth, myHeight, arcWidth, arcWidth);
            g.drawRoundRect(1, 1, myWidth - 2, myHeight - 2, arcWidth - 2, arcWidth - 2);
            g.setDrawingStyle(Graphics.DRAWSTYLE_AAPOLYGONS, aaLines);
            g.setColor(prevColor);
            super.paint(g);
        }
    
        public void focusChanged(Field field, int eventType) {
            if (field == editField) {
                switch (eventType) {
                case FOCUS_GAINED:
                case FOCUS_LOST:
                    adjustBorderColor();
                    break;
                default:
                    break;
                }
            }
        }
    
        private void adjustBorderColor() {
            int nextColor;
            if (editField.isFocus()) {
                nextColor = activeBorderColor;
            } else {
                nextColor = inactiveBorderColor;
            }
            if (borderColor != nextColor) {
                borderColor = nextColor;
                invalidate();
            }
        }
    }
    
  • Using a function from another class

    Information: Blackberry JDE 7.1.0

    BlackBerry 9930 Simulator - V 4.0.0.141

    The title of the topic seems simple, but I'm actually trying to use a X of class A function inside a function Y of class B and the GET, the value returned by X to a variable in B.

    Let me start by explaining what I currently have and then go on what I'm doing.

    I am using this class, the code for which I found online, to create a scrollable multi-line textbox.

    public class TextBoxField extends VerticalFieldManager {
    
          //define some variables to be used
          //in the class
          private int managerWidth;
          private int managerHeight;
          private EditField editField;
    
          public TextBoxField(int width, int height) {
                super(Manager.NO_VERTICAL_SCROLL);
                managerWidth = width;
                managerHeight = height;
    
                VerticalFieldManager vfm =
                    new VerticalFieldManager
                      (Manager.VERTICAL_SCROLL);
    
                  editField = new EditField(){
                    public void paint(Graphics g) {
                    getManager().invalidate();
                    super.paint(g);
                  }
                };
    
                vfm.add(editField);
                add(vfm);
              }
    
          public void paint(Graphics g) {
              super.paint(g);
              g.drawRect(0, 0, getWidth(), getHeight());
            }
    
          public void sublayout(int width, int height) {
              if (managerWidth == 0) {
                managerWidth = width;
              }
              if (managerHeight == 0) {
                managerHeight = height;
              }
              super.sublayout(managerWidth, managerHeight);
              setExtent(managerWidth,managerHeight);
            }
    
          public String getText() {
                return editField.getText();
              }
              public void setText(String text) {
                editField.setText(text);
              }
            }
    

    Then in another class that I created a "Set" function that instantiates the class textbox, to create two text boxes and a richfieldtext, add them to a HorizontalFieldManager and return the HorizontalFieldManager.

     HorizontalFieldManager Set(int set){
            HorizontalFieldManager hr1=new HorizontalFieldManager(FIELD_HCENTER);
    
            RichTextField set1 = new RichTextField("SET " + set + ":"){
                protected void layout(int width, int height)
                {
                    super.layout(75,30);//Width and height according to the button name;
                    setExtent(75,30);//width and height according to the button name;
                }
            };
            set1.setPadding(10, 5, 10, 10);
            TextBoxField set1W = new TextBoxField(40,25);
            set1W.setPadding(10, 5, 10, 0);
            TextBoxField set1R = new TextBoxField(40,25);
            set1R.setPadding(10, 5, 10, 0);
    
            hr1.add(set1);
            hr1.add(set1W);
            hr1.add(set1R);
    
            return hr1;
        }
    

    Now in my main class I call this function to add a 'Set' on the screen using:

    add(Set(1));
    

    For the creation of the 'Set' function instead of using the instance of the textbox class in the main class itself, it is because I will create several 'sets '.

    Now, as you can see, there is a public String getText() function in the TextBoxField() that returns the value of the editField. What I need to do, is to get the value in this field, once you press a button.

    I have the code for the function button, so this isn't a matter of concern. However I do not know how to retrieve the editField value when the button is pressed. I can get the value inside the Set()function, using the:

    String getval = set1W.getText();
    

    but can't reach it from the outside. I don't even know if it's possible in the first. If it is not could someone suggest a way where I could retrieve these values.

    Any help is appreciated.

    Thank you.

    Thanks for the suggestion. I found another workaround solution. Essentially implementation of an array of TextBoxFields and then pass them one by one the "Set()" method

    I tried this at the start before posting here, but due to a careless mistake when you declare the array of TextBoxFields, I couldn't make it work.

    In any case, the topic can be closed now, because the problem has been resolved. Thank you.

  • Implementation of the text box

    Hello

    I need to put in place the text box in my application. I have created custom textbox his works well, enter when the button I get no second line, but the focus moves to the next field. Please

    class TextBox extends VerticalFieldManager {
        int managerWidth;
        int managerHeight;
        private EditField editField;
    
        int width = Display.getWidth()-70;
        int height = 18;
        int maxvalue=2000;
        public TextBox() {
            super(Manager.NO_VERTICAL_SCROLL);
            managerWidth = width;
            managerHeight = height;
            VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL |               VerticalFieldManager.FIELD_VCENTER);
            // vfm.setPadding(3,0,0,5);
            editField = new EditField("","",maxvalue,Field.FIELD_HCENTER){
                public void paint(Graphics g) {
                    getManager().invalidate();
                    this.setFont(Utilities.getAppFont());
                    super.paint(g);
                }
            };
            vfm.add(editField);
            add(vfm);
        }
        public void paint(Graphics graphics) {
            graphics.setColor(Color.WHITE);
            graphics.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
            graphics.setColor(0x00000000);
            super.paint(graphics);
            graphics.setColor(0x0BBBBBB);
            graphics.drawRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
        }
        public void sublayout(int width, int iHeight) {
            if (managerWidth == 0) {
                managerWidth = width;
            }
            if (managerHeight == 0) {
                managerHeight = iHeight;
            }
            super.sublayout(managerWidth, managerHeight);
            int iNumFields = getFieldCount();
            int iYPos = 5;
            int iXPos = 5;
            Field fField = null;
    
            for (int i = 0; i < iNumFields; i++) {
                fField = this.getField(i);
                setPositionChild(fField, iXPos, iYPos);
                //get height for layout and height
                int tmpHeight = managerHeight;
                //draw field
                layoutChild(fField, getWidth(), tmpHeight);
                iYPos = iYPos + tmpHeight+5;
            }
            //now we reset our extent to include padding   
    
            this.setExtent(managerWidth, Math.max(iYPos, getPreferredHeight()));
            setVirtualExtent(managerWidth, Math.max(iYPos, getPreferredHeight()));
        }
        public int getPreferredHeight() {
            height = 5;
            int iNumFields = getFieldCount();
            for (int i = 0; i < iNumFields; i++) {
                height += getHeight(getField(i))+5;
            }
            return height;
        }
    
        private int getHeight(Field f) {
            return Math.max(Math.max(f.getContentHeight(), f.getHeight()),f.getPreferredHeight());
        }
        public String getText() {
            return editField.getText();
        }
        public void setText(String text) {
            editField.setText(text);
        }
        public void setMaxSize(int max) {
            editField.setMaxSize(max);
        }  
    
    }
    

    Help me create the text box

    Sorry not looked seriously at your code, but there are some problems with it I think.

    Rather than trying to fix your code, it does the job for you?

    http://supportforums.BlackBerry.com/T5/Java-development/TextBoxField-revisited/Ta-p/548410

  • the value of the digital inputs to change the field

    Hi all

    I have an edit field that has a digital text filter that only accepts phone numbers. Users have the choice to load these numbers from address book or direct entry.

    I used the digital filter to allow only numbers. .

    But when I tried to load these address book.  with editField.setText (phoneNum); It is to throw IllegalArgumentException.

    How to set digital inputs to the editField?

    Hi thanks for all your entries!

    My issued are resolved. I used BasicEditField aulieude EditField to solve this problem. the basicedit field allows the digital text and it solved the problem.

    Thanks for all your interest...

  • TextBox in Blackberry

    TextBox as in AWT in Blackberry...

    SerializableAttribute public class TextBox extends VerticalFieldManager {}

    private int managerWidth;
    private int managerHeight;
    Private EditField editField.
        
    public TextBox (int width, int height) {}
    Super (Manager.NO_VERTICAL_SCROLL);
    managerWidth = width;
    managerHeight = height;
    VerticalFieldManager = vor
    new VerticalFieldManager
    (Manager.VERTICAL_SCROLL);

    editField = new EditField()
    {
    {} public void paint (Graphics g)
    getManager () .invalidate ();
    Super.Paint (g);
    }
    };
    VFM. Add (editField);
    Add (VFM);
    }

    protected boolean trackwheelClick (int arg0, int arg1) {}
    Returns true;
    }
    protected void sublayout (int width, int height) {}
    If (managerWidth == 0) {}
    managerWidth = width;
    }
    If (managerHeight == 0) {}
    managerHeight = height;
    }
    Super.sublayout (managerWidth, managerHeight);
    setExtent (managerWidth, managerHeight);

    }

    protected void paint (Graphics arg0) {}
            
    FontFamily fontFamily = null;
    try {}
    fontFamily = FontFamily.forName ("Arial");
    } catch (ClassNotFoundException e) {}
    Generative TODO catch block
    e.printStackTrace ();
    }
    this.setFont (fontFamily.getFont (Font.PLAIN, Display.getHeight () / 20));
    arg0.drawRect (0, 0, getWidth(), getHeight());
    Super.Paint (arg0);
    }
        
    public String getText()
    {
    Return editField.getText ();
    }
    {} public void setText (String text)
    editField.setText (text);
    }

    }

    Simon and Peter needs your help in my question recently sent from the ObjectChoiceField in OS 5.0...

    PLS, take a look on this...

  • extension textfied

    Hello

    I have a textfield of a certain fixed size, but I want the user to be enter the text that will be probably larger than the size of the textfield (e.g. e-mail address). How do get you this text to fit in the textfield without increasing the size of the field? For example, I want it works the same way as entering a url in a browser that is larger that the url field works. How to achieve this?

    Thank you

    Somewhere on this forum are a few solutions to your own domain.  It's the solution that I use (in the forum).

    package com.smartmech.bb;
    
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.component.EditField;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    
    //Fixed width/height scrollable text field
    public class TextBoxField extends VerticalFieldManager {
    
          //define some variables to be used
          //in the class
          private int managerWidth;
          private int managerHeight;
          private EditField editField;
    
          public TextBoxField(int width, int height) {
                super(Manager.NO_VERTICAL_SCROLL);
                managerWidth = width;
                managerHeight = height;
    
                VerticalFieldManager vfm =
                    new VerticalFieldManager
                      (Manager.VERTICAL_SCROLL);
    
                  editField = new EditField(){
                    public void paint(Graphics g) {
                    getManager().invalidate();
                    super.paint(g);
                  }
                };
    
                vfm.add(editField);
                add(vfm);
    
          } //TextBoxField
    
          public void paint(Graphics g) {
              super.paint(g);
              g.drawRect(0, 0, getWidth(), getHeight());
          }
    
          public void sublayout(int width, int height) {
              if (managerWidth == 0) {
                managerWidth = width;
              }
              if (managerHeight == 0) {
                managerHeight = height;
              }
              super.sublayout(managerWidth, managerHeight);
              setExtent(managerWidth,managerHeight);
          }
    
          public String getText() {
            return editField.getText();
          }
          public void setText(String text) {
            editField.setText(text);
          }
    
    } //TextBoxField
    

    You will have to tweak it to scroll the opposite effect.

  • Automatically resize the custom text - TextBox

    Hi all, I have a box of text customized with gratitude of this site. I like the idea of having the text resize automatically when it reaches the length of the text for the full text box will always be in view, limiting the amount of characters, of course.

    Could someone help me what do I do?

    package com.google.zxing.client.rim;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Manager;
    
    import net.rim.device.api.ui.component.EditField;
    
    import net.rim.device.api.ui.container.VerticalFieldManager;
    public class MyTextBoxField extends VerticalFieldManager {
    
      //define some variables to be used
      //in the class
      private int managerWidth;
      private int managerHeight;
      private EditField editField;
    
       public MyTextBoxField(int width, int height) {
        super(Manager.NO_VERTICAL_SCROLL);
        managerWidth = width + 5;
        managerHeight = height + 5;
    VerticalFieldManager vfm =
          new VerticalFieldManager
            (Manager.VERTICAL_SCROLL);
    
        editField = new EditField(){
          public void paint(Graphics g) {
          getManager().invalidate();
          g.setColor(0x999999);
          Font font = this.getFont().derive(Font.PLAIN, 35);
         g.setFont(font);
    //Log.info("B get WIDTH " + b.getWidth());
    
          super.paint(g);
        }
      };
        Font font = this.getFont().derive(Font.PLAIN, 35);
         editField.setFont(font);
      vfm.add(editField);
      add(vfm);
    }
    
    public void paint(Graphics g) {
    //Log.info("This is button size " + textButton.getHeight());
      super.paint(g);
      g.setColor(0x999999);
      Font font = this.getFont().derive(Font.PLAIN, 35);
      g.setColor(0x999999);
         g.setFont(font);
      g.drawRect(0, 0, getWidth(), getHeight());
    }
    
    public void sublayout(int width, int height) {
      if (managerWidth == 0) {
        managerWidth = width;
      }
      if (managerHeight == 0) {
        managerHeight = height;
      }
      super.sublayout(managerWidth, managerHeight);
      setExtent(managerWidth,managerHeight);
    }
    
    public String getText() {
        return editField.getText();
      }
      public void setText(String text) {
        editField.setText(text);
      }
    }
    

    Try changing the method object with below:

    public void paint(Graphics g)
    {
        super.paint(g);
        g.drawRect(0, 0, getWidth(), getHeight());
    
        Font font = editField.getFont();
        g.setColor(0x999999);
        String text = editField.getText();
    
        int totalWidth = this.getWidth() - 10;
        int fontHeight  = font.getHeight();
        for(int fontSize = fontHeight; fontSize >= 5; --fontSize)
        {
            //length of the text
            int length = Font.getDefault().derive(Font.PLAIN,
                         fontSize).getAdvance(text);
            if(length > totalWidth)
            {
                //derived font for the fontSize
                font = Font.getDefault().derive(Font.PLAIN, fontSize);
                continue;
            }
        }
    
        editField.setText(text);
        editField.setFont(font);
    }
    

    Concerning

    Bika

  • Need help with ContextMenu in CustomEditField

    Hello world

    I created a CustomEditField which, when I type beyond the width of the EditField, he's not going to a new line, but rather 'continue' on the same line (and hide the text).

    I'm looking to correctly override makeContextMenu, so that when I click on the Menu OR click on the trackball (with the CustomEditField in short), a ContextMenu will come with just a 'Search' element inside. (Similar to 'Send' in the BBM text field).

    I'd appreciate any help, here is my current code:

    public class CustomEditField extends VerticalFieldManager {
    
     private int managerWidth; private int managerHeight;    private EditField editField;
    
        public CustomEditField(final String label, int width) {
    
         super(Manager.NO_VERTICAL_SCROLL);        managerWidth = width;
    
           VerticalFieldManager vfm = new VerticalFieldManager(              Manager.VERTICAL_SCROLL);
    
           editField = new EditField() {         public void paint(Graphics g) {               getManager().invalidate();                super.paint(g);           }
    
               protected void onFocus(int direction) {               if (getText().equals("") || getText().equals(label)) {                    setText("");              }         }
    
               protected void onUnfocus() {              if (getText().equals(label) || getText().equals("")) {                    setText(label);               }         }     };
    
          editField.setText(label);     vfm.add(editField);       add(vfm); }
    
       public void paint(Graphics g) {       super.paint(g);
    
         int oldColor = Color.GRAY;        // int oldAlpha = g.getGlobalAlpha();
    
           // g.setGlobalAlpha(0x88);        g.setBackgroundColor(0x00EF3825);     g.setColor(Color.BLACK);      g.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);     g.setColor(oldColor);     // g.setGlobalAlpha(oldAlpha);        super.paint(g);   }
    
       public void sublayout(int width, int height) {
    
          if (managerWidth == 0) {          managerWidth = width;     }     if (managerHeight == 0) {         managerHeight = height;       }     super.sublayout(managerWidth, getPreferredHeight());      setExtent(managerWidth, getPreferredHeight());    }
    
       class ContextMenuItem extends MenuItem {      public ContextMenuItem() {            super("Search", 20, 10);      }
    
           public void run() {           // search();      } }
    
    }
    

    Thank you!

    Solved by the following code to the screen:

     public void makeMenu(Menu menu, int instance) {
            super.makeMenu(menu, instance);
            // add these items to the full menu
            if (instance == Menu.INSTANCE_DEFAULT) {
                menu.add(new SearchMenuItem());
                menu.add(new BrowseMenuItem());
                menu.add(new QueuesMenuItem());
            }
            if (instance == Menu.INSTANCE_CONTEXT) {
                menu.add(new ContextMenuItem());
            }
    
        }
    
  • How to get out the address book?

    When I choose a contact, I can return to the editField interface and as SUCH get set to the editField,

    but now if I didn't chosse contact, I want to return to the editField interface, it shows Nullpointer Exception.

    so, how can I get out of address book?

    showAddressBook my code:

    public void showAddressBook() {}
    try {}
    Contact list BlackBerryContactList = (BlackBerryContactList) BlackBerryPIM.getInstance () .openPIMList (BlackBerryPIM.CONTACT_LIST, BlackBerryPIM.READ_WRITE);
    Contact BlackBerryContact = (BlackBerryContact) contactList.choose (null, BlackBerryContactList.AddressTypes.EMAIL, true);
      
    Portable chain = "";
    int numValues = 0;
    numValues = contact.countValues (BlackBerryContact.TEL);
      
    for (int i = 0; i)< numvalues;="" i++)="">
    If (contact.getAttributes (BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) {}
    Cell = contact.getString(BlackBerryContact.TEL, i);
    break;
    }
    }
             
    editField.setText (mobileNumber);
    } catch (PIMException ex) {}
    ex.printStackTrace ();
    }
    }

    If the user decides to not choose a contact, you get null as a return value. your code should check this.

  • Problem with EditField?

    Hello

    I created an EditField and iam trying to make a rectangular shape of it, but the problem is while typing cursor comes from new line and it increases the width of the textfield.  Please find the picture below.  I expect that letters should be on the left is not down. For example, in the browser of the Simulator, there are a TextBox it behave like that.  I added the rectangle to textfiled I think it takes the screen.  Please provide a useful for the same code snippet.  Thanks advanced

    edit = new EditField("", "",50, EditField.FILTER_DEFAULT | EditField.NO_NEWLINE)
            {
                protected void layout(int maxWidth, int maxHeight) {
                    super.layout(137, this.getHeight());
                    setExtent(137, this.getHeight());
                }
                public void paint( Graphics graphics ) {
                    graphics.setColor(Color.RED);
                    System.out.println("!!!!!!!!!!!!!!!!!Width :: "+getWidth());
                                    graphics.setColor(Color.BLACK);
                    super.paint(graphics);
                }
            };
    

    With the recent restructuring of the site web, Rim have moved the magazines.  Try here:

    http://NA.BlackBerry.com/eng/devjournals/resources/journals/jul_2005/creating_textbox_field.jsp

  • EditField problem!

    Hi every1

    I was faced with a problem when adding a text field on screen.

    When I'm trying to add a field for a GridFieldmanager editing, I m getting an EXCEPTION 'ILLEGALARGUMENT' and ending of app.

    Here I m using the object persistent 2 store text in of editfield

    Infact I m error, when I m 2 access the same screen twice, by train, but not in the first attempt. Initially I m 2 can access screen with success, but in my second attempt I m get error at the particular point dat dat

    Help me... Urgent!

    Concerning

    Kiran

    http://www.BlackBerry.com/developers/docs/6.0.0api/NET/rim/device/API/UI/component/BasicEditField.ht...

    Throws:
    IllegalArgumentException - if the text cannot be entered in an edit field.

    My guess would be that you have a filter set on the field and try to define a text that is in conflict with it, but without more information, it is difficult to say.

  • problem of return back in EditField

    Hello

    I have an EditField. When I run an editfield.backspace (1) when the cursor position is 1, I get an IndexOutofBounds exception.

    Any ideas on how to solve this problem?

    Thank you

    Hi, please tell me your requirement in terms of what you want to do?, I understand your code, but just tell me what is the feature.

Maybe you are looking for

  • Satellite A300 - multimedia keys need driver for Win7

    Hello, I searched these drivers because win 7 appeared on the market. And I can't find these drivers anywhere.Can someone please help me find them? I don't speak of the multimedia keys, I got on the cell: "play/pause/back/mute...". "etc. Thank you fo

  • Satellite L200: Why LCD freezes and lines to the LCD display displayed during charging?

    Hello! I'm new here and Ive had some problems with my L200. Whenever I charge my phone while using my LCD monitor freezes and there is a bit of running lines that appear in the monitor.The only way I can use it is to unplug the charger and run it thr

  • Care + Apple Apple Watch

    can I buy a Best Buy Apple Watch without Apple care so in a few weeks purchase, care of the Apple Apple help please!

  • Fs9 not opening - identified problem but need help repair

    I want to thank you in advance for your time. I am trying to install and play flight sim 2004 on windows 7 - a x 64 sys - and when I open fs9.exe splash screen or anything really fails to display. I think that is the problem, is that there is no reco

  • Compac pressario sr5129uk NVLDDMKM getting failed in Vista

    Help, please Vista home 32-bit, computer crashes and freezes and I get NVLDDMKM failed and recovered, the colors in the disappearing from the screen, tried to download the latest drivers, but still does not, in the case of safe mode all right. Driver