box arround editfield

is it possible to have arround textfield boxes, how?

thaks advances

RIM API 4.2 has no classes to control the field borders.

Optionally, you can use the class javax.lcdui instead of rim.ui classes and draw your fields on canvas.

Tags: BlackBerry Developers

Similar Questions

  • CustomTextBox align

    Hi all

    I use code kindly offered online by Dorian.

    Now, I am trying to align this text box toward the Center.

    Does anyone know what I need to change to achieve this please?

    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.ui.component.BasicEditField;
    import net.rim.device.api.system.EncodedImage;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.system.Characters;
    import net.rim.device.api.math.Fixed32;
    import net.rim.device.api.ui.DrawStyle;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.container.MainScreen;
    
    public class CustomTextBox2 extends Manager{    /**     * Default margins     */
        private final static int DEFAULT_LEFT_MARGIN = 0;
    
    private final static int DEFAULT_RIGHT_MARGIN = 10;
    private final static int DEFAULT_TOP_MARGIN = 5;
    private final static int DEFAULT_BOTTOM_MARGIN = 5;        /**     * Default paddings     */
    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;
    /**     * Margins around the text box     */
    private int topMargin = DEFAULT_TOP_MARGIN;
    private int bottomMargin = DEFAULT_BOTTOM_MARGIN;
    private int leftMargin = DEFAULT_LEFT_MARGIN;
    private int rightMargin = DEFAULT_RIGHT_MARGIN;
    /**     * Padding around the text box     */
    private int topPadding = DEFAULT_TOP_PADDING;
    private int bottomPadding = DEFAULT_BOTTOM_PADDING;
    private int leftPadding = DEFAULT_LEFT_PADDING;
    private int rightPadding = DEFAULT_RIGHT_PADDING;
    /**     * Amount of empty space horizontally around the text box     */
    private int totalHorizontalEmptySpace = leftMargin + leftPadding
            + rightPadding + rightMargin;
    /**     * Amount of empty space vertically around the text box     */
    private int totalVerticalEmptySpace = topMargin + topPadding
            + bottomPadding + bottomMargin;
    /**     * Minimum height of the text box required to display the text entered     */
    private int minHeight = getFont().getHeight() + totalVerticalEmptySpace;
    /**
     * Width of the text box     */
    private int width;
    /**     * Height of the text box     */
    private int height = 45;
    /**     * Background image for the text box     */
    private EncodedImage backgroundImage;
    /**     * Bitmap version of the backgroundImage.
     * Needed to reduce the calculation overhead incurred by
     * scaling of the given image
     * and derivation of Bitmap from the
     * EncodedImage every time it is needed.
     */
    private Bitmap bitmapBackgroundImage;
    /**
     * The core element of this text box
     */
    private EditField editField;
    MainScreen theScreen;
    //private BasicEditField editField;
    //private String entireText;
    public CustomTextBox2(int width2, int height, MainScreen aScreen)
    {
         super(0);
        theScreen = aScreen;
        // Let the super class initialize the core
    
        width = width2 + 20;
        // An edit field is the sole field of this manager.
        editField = new EditField();
        //editField = new CustomEditField();
        add(editField);
    }
    
    /*
    public CustomTextBox2(EncodedImage backgroundImage)
    {
        this();
    
    setBackgroundImage(backgroundImage);
        }
     * */
    
        public void setSize(int width, int height)
        {
            boolean isChanged = false;
            if (width > 0 // Ignore invalid width
                    && this.width != width)
            {
                this.width = width;
                isChanged = true;
            }
            // Ignore the specified height if it is less
            // than the minimum height required to display the text.
            if (height > minHeight && height != this.height)
            {
                this.height = height;
                isChanged = true;
            }
            // If width/height has been changed and background image
            // is available, adapt it to the new dimension
            if (isChanged == true && backgroundImage != null)
            {
                bitmapBackgroundImage = getScaledBitmapImage(backgroundImage,
                        this.width - (leftMargin+rightMargin),
                        this.height - (topMargin+bottomMargin));
    
            }
        }
    
        public void setWidth(int width)
        {
            if (width > 0 && width != this.width)
            {
                this.width = width;
                // If background image is available, adapt it to the new width
                if (backgroundImage != null)
                {
                    bitmapBackgroundImage = getScaledBitmapImage(backgroundImage,
                            this.width - (leftMargin+rightMargin),
                            this.height - (topMargin+bottomMargin));
                }
            }
        }
        public void setHeight(int height)
        {
            // Ignore the specified height if it is
            // less than the minimum height required to display the text.
            if (height > minHeight)
            {
                this.height = height;
                // If background image is available, adapt it to the new width
    
                if (backgroundImage != null)
                {
                    bitmapBackgroundImage = getScaledBitmapImage(backgroundImage,
                            this.width - (leftMargin+rightMargin),
                            this.height - (topMargin+bottomMargin));
                }
            }
        }
        public void setBackgroundImage(EncodedImage backgroundImage)
        {
            this.backgroundImage = backgroundImage;
            // Consider the height of background image in
            // calculating the height of the text box.
            // setHeight() does not ensure that specified
            // height will be in effect, of course, for valid reasons.
            // So derivation of Bitmap image in the setHeight() method is not sure.
            setHeight(backgroundImage.getHeight() + topMargin + bottomMargin);
            if (bitmapBackgroundImage == null)
            {
                bitmapBackgroundImage = getScaledBitmapImage(backgroundImage,
                        this.width - (leftMargin+rightMargin),
                        this.height - (topMargin+bottomMargin));
            }
        }
        /**     * Generate and return a Bitmap Image scaled according
         * to the specified width and height.
         *
         * @param image     EncodedImage object
         * @param width     Intended width of the returned Bitmap object
         * @param height    Intended height of the returned Bitmap object
         * @return Bitmap object     */
        private Bitmap getScaledBitmapImage(EncodedImage image, int width, int height)
        {
            // Handle null image
            if (image == null)
            {
                return null;
            }
            int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
            int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
            int requiredWidthFixed32 = Fixed32.toFP(width);
            int requiredHeightFixed32 = Fixed32.toFP(height);
            int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
            int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
            image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
            return image.getBitmap();
        }
        protected void sublayout(int width, int height)
        {
            // We have one and only child - the edit field.
            // Place it at the appropriate place.
            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)    {
            // Draw background image if available, otherwise draw a rectangle
            if (bitmapBackgroundImage == null)
            {
                //graphics.drawRect(leftMargin, topMargin,                                 width - (leftMargin+rightMargin),                                 height - (topMargin+bottomMargin));
                graphics.setColor(0x000000);
                graphics.drawRoundRect(leftMargin, topMargin,
                        width - (leftMargin+rightMargin),
                        height - (topMargin+bottomMargin), 15, 15);
                graphics.setColor(0xffffff);
                graphics.fillRoundRect(leftMargin, topMargin,
                        width - (leftMargin+rightMargin),
                        height - (topMargin+bottomMargin), 15, 15);
            }
            else
            {
                graphics.drawBitmap(leftMargin, topMargin,
                        width - (leftMargin+rightMargin),
                        height - (topMargin+bottomMargin),
                        bitmapBackgroundImage, 0, 0);        }
            // Determine the rightward text that can fit into the visible edit field
            EditField ef = (EditField)getField(0);
            String entireText = ef.getText();
            boolean longText = false;
            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)
            {
                // Force the edit field display only the truncated text
                ef.setText(textToDraw);
                // Now let the components draw themselves
                super.paint(graphics);
                // Return the text field its original text
                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)
        {
           Log.info("KEYCHAR " + ch);
            switch(ch){
    
                case Characters.ENTER:
                    try
            {    Log.info("KEYCHAR 1");
                       // theScreen.textButton.getChangeListener().fieldChanged(theScreen.textButton, theScreen.textButton.getIndex());
       Log.info("KEYCHAR 2");
              // f.getChangeListener().fieldChanged(f, f.getIndex());
            }
            catch (Exception e)
            {
            Log.info("Error at fcn" + e);
            }
                    return true;
    
            }
    Log.info("KEYCHAR 0");
    //theScreen.textButton.getChangeListener().fieldChanged(theScreen.textButton, theScreen.textButton.getIndex());
    
            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);
        }
       }
    

    You are missing a centerpiece - the ability to set the bits of style on this field. If you add a constructor that accepts a parameter of long style and has great (style) as the first operator, you should be able to create with the FIELD_HCENTER style bit and add it to a Manager honor this indicator (for example, VerticalFieldManager).  Then it will be automatically centered horizontally by the parent Manager.

    It is the same on FIELD_VCENTER and, say, HorizontalFieldManager.

  • TextField inside the dialog box?

    I saw on games like brickbreaker. They have a dialog box to come and ask you to enter your user name. I tried a little differently, but I have not had luck with it yet. Can someone point me to a tutorial or just after a line or two of code on how to do it?

    Thank you

    In your TestDialog class, add this method:

        public final class TestDialog extends Dialog{
    
            private EditField userNameField;
    
            public TestDialog(String choices[], int values[]){
                super("Enter a username", choices, values, Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), Dialog.GLOBAL_STATUS);
                userNameField = new EditField("User Name: ", "", 50, EditField.EDITABLE);
                net.rim.device.api.ui.Manager delegate = getDelegate();
                if( delegate instanceof DialogFieldManager){
                    DialogFieldManager dfm = (DialogFieldManager)delegate;
                    net.rim.device.api.ui.Manager manager = dfm.getCustomManager();
                    if( manager != null ){
                        manager.insert(userNameField, 0);
                    }
                }
            }    
    
            public String getUsernameFromField(){
              return userNameField.getText();
            }
    
        }
    

    Then change your main class to use:

            if(pw.doModal() == Dialog.OK){
                System.out.println(pw.getUsernameFromField());
            }
    
  • 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();
            }
        }
    }
    
  • EditField listener for typing

    I'm trying to create a text using the EditField box, when you type a character his listener is invoked.  This must be done each time a character is entered.

    I try to achieve an effect when a user types in the search box start automatically, for example a list of names, when the user starts typing, it will find and bring back what the user types, so if C is entered all names starting with C would return, if they then type CO, all names starting with "CO" will be returned.

    I had no problem creating the text box, I tried to add the handler in the following way,

            FieldChangeListener bhandler = new FieldChangeListener()
            {
                public void fieldChanged(Field field, int context)
                {
                    System.out.println("woohoo");
                }
            };
    
            search.setChangeListener(bhandler);
    

    Any help would be appreciated.

    Try this

    Search for EditField = new EditField ("search for:",");
    search.setChangeListener (new FieldChangeListener() {}

    ' Public Sub fieldChanged (field field, int context) {}
    System.out.println ("Woot");

    }

    });

  • Question EditField and border

    Hello!

    I had a problem of design. I did something I thought I would work, but I think that I am so close to get it. I have 2 is the image I updated my EditField as boder when unfocus the image has a WHITE background and what door another color. I have a few lines in unfocus and the development of the code field method and I put the border with these images. But when I run on the Simulator, the field has a white rectangle inside. So, I added a few lines and I put a background color when the field is developed. But I got something like that.

    Unfocus:

    Focus:

    How can I erase this white part? or maybe is there something I have missed?

    I hope you help me!

    Concerning

    Hello! Thanks for your review!

    Well, I create a custom EditField and here is a part of the code:

        private int mHColor = -1;
        public void setHightlightColor(int color) {
            mHColor = color;
        } 
    
        protected void onFocus(int direction) {
            invalidate();
            setBorder(BorderFactory.createBitmapBorder(new XYEdges(4, 7, 4, 7),Bitmap.getBitmapResource("img/box.png")));
        }
    
        protected void onUnfocus() {
            invalidate();
            setBorder(BorderFactory.createBitmapBorder(new XYEdges(4, 7, 4, 7),Bitmap.getBitmapResource("img/boxu.png")));
        } 
    
       public void paint(Graphics g) {
          if (-1 != mHColor && getManager().isFocus()) {
             g.setBackgroundColor(mHColor);
             g.clear();
          }
          int prevColor = g.getColor();
          g.setColor(prevColor);
          g.clear();
          g.setGlobalAlpha(200);
          super.paint(g);
        }
    

    And in my screen, I called like this:

       _inputField.setHightlightColor(0xFFFFBD);/// FFE9AF
       _inputField.setBorder(BorderFactory.createBitmapBorder(new XYEdges(4, 7, 4, 7),Bitmap.getBitmapResource("img/boxu.png")));
    

    You see how I use a bitmapborder. I create 2 images: one with white background and one with yellow background.

    I hope you can help me!

    Kind regards.

    PS: I use 4.6.0 SDK

  • How to convert the Editfield value chain

    Greetings

    Please help me to convert the editfield in sting.

    with the help of toString (), it does not convert it to a string.

    Help, please

    concerning

    Anthony singh

    arkadyz is located...

    but you must put this line in an event thread... because you enter the value in an editfield dynamically (at runtime) he must go and look after that the value has been added...

    As you can use a button... When you click on it, then the value is extracted from the help:

    final String text = SmsField.getText ();

    and your dialog box appears...

  • Question of the development of EditField and LabelField in HorizontalFieldManager

    I actually want a custom editfield (a label with a textbox), when he got focus on this textbox draws a border of climax, and I want the label got the same effect, however, I drew a border outside the text easily because of the text box could receive focus , here is my code:

    public class MyTextField extends EditField
    {
        public MyTextField()
        {
            super();
        }
    
        public void layout(int width, int height)
        {
            super.layout(width, height);
        }
    
        protected void paint(Graphics g)
        {
            if(g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS))
            {
                setBorder(BorderFactory.createRoundedBorder(new XYEdges(6, 6, 6, 6), 0x186DEF, Border.STYLE_SOLID));
            }else{
                setBorder(BorderFactory.createRoundedBorder(new XYEdges(6, 6, 6, 6), Color.GRAY, Border.STYLE_SOLID));
            }
    
            super.paint(g);
         }
    }
    

    And I use this code to show in screen

           HorizontalFieldManager hfm=new HorizontalFieldManager();
            LabelField label=new LabelField("something");
            MyTextField text=new MyTextField();
    
            hfm.add(label);
            hfm.add(text);
            add(hfm);
    

    Is there a way to implement that when the textbox has got the update at the same time also changed the color of the text of the label.

    set a Boolean flag that you record in paint, set it on the ground (from outside) and invalid call to redraw.

  • Doubt in the dialog box

    I have my custom dialog box, which contains the text edit tracking ok Cancel button, when I press ok and Cancel button, the appropriate events are scheduled

    In my code, whatever i add (values that I might add) in the editfield of the dialog box, it is entered in the form, even if I press Cancel button, how to achieve this?

    The code examples will be useful.

    Concerning

    Rakesh Shankar.P

    I think that this example corresponds to what you are looking for.

    -How to create a custom dialog box

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800256/...

  • Add Rectangularbox to the EditField giving unneccessay verical bars?

    Hello

    I am trying to add rectangluar gray box in the EditField it contains blacktext with code below and it gives a few extra verical between letters bars while moving the arrows inside the text, it is shown in the attachment.

    Please correct my code or if you have any comments about the code covers this send me please.  Advanced thank you for your great help.

    EditField edit = new EditField("", "Search News", 20, EditField.FILTER_DEFAULT)
            {
                private XYRect xyrect=new XYRect();
                protected void paint(Graphics graphics) {
                        xyrect=graphics.getClippingRect();
                        graphics.setColor(Color.GRAY);
                        graphics.drawRect(xyrect.x,xyrect.y,xyrect.width,xyrect.height);
                        graphics.setColor(Color.BLACK);
                        super.paint(graphics);            } 
    

    Instead of getClippingRectangle(), just try calling getHeight() and getWidth() on the field to get your height and width.

    Something like this:

     
      graphics.setColor(Color.GRAY);
      graphics.drawRect(0,0,getWidth(),getHeight);
    
  • Doubts in the dialog box

    Hello

    I have my doubts about dialogue box, I have the dialogue box, with edtfield in it, if I enter anything in the box of dialogue, even if I press cancel it just passes values

    what I want, that is, if I press ok, button must pass, if I press Cancel, it must cancel and close the dialog box, which is command must I use for it

    public final class CustomDialog extends Dialog
    {
        EditField entryField;
        SeparatorField s,s1;
        Font ft;
    
        public CustomDialog()
        {
          //super(Dialog.D_OK, "Custom Dialog", 1,Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Manager.FOCUSABLE);
          super(Dialog.D_OK_CANCEL,"Medication Settings",1,Bitmap.getPredefinedBitmap(Bitmap.INFORMATION),Manager.FOCUSABLE);
          s=new SeparatorField();
          add(s);
          entryField = new EditField("Enter Medication type: ", "", 50, EditField.EDITABLE|EditField.NO_NEWLINE);
          ft=this.getFont().derive(FontFamily.SCALABLE_FONT, 18);
          entryField.setFont(ft);
          add(entryField);
          s1=new SeparatorField();
          add(s1);
    
        }
    
       public String getText()
       {
          return entryField.getText();
       //    return "code";
       }
    

    This is the dialog box, I use

    Anh help on this year.

    Concerning

    Rakesh Shankar.P

    Try how to handle the OK and CANCEL button click

    CustomDialog dialog = new CustomDialog();int result = dialog.doModal();if (result == Dialog.OK){// do your on OK processString text = dialog.getText();}else if (result == Dialog.CANCEL){dialog.close();}
    
  • EditField when it is full the text does not scroll

    Hello

    Below custom editfield extends EditField. My problem is that the user Pat and field gets complete with text, when the user reaches the end of visible display of the field the text scrolls does'nt user types continuously.

    Should I use a different type of field?

    Any help much appreciated.

    SerializableAttribute public class CustomEditField extends EditField {}
    private members of the class CustomEditField
    defaultFont fonts private;
    used to get the default font
    private string text;

    private int width;
    used to specify the default width of the table cells

    constructor calls the constructor of the superclass
    public CustomEditField (label As String, String initialValue, int maxNumChars,
    long style, int width) {}
    Super (label, initialValue, maxNumChars, style);
    This.Width = width;
    }

    replaces the functionality of getPreferredWidth default to return to a fixed rate
    Width
    public int getPreferredWidth() {}
    / * defaultFont = Font.getDefault ();
    Text = "0000000000";
    Return defaultFont.getAdvance (text); * /
    return this.width;

    }

    replaces the default layout features to set the width of the table
    cell
    Protected Sub layout (int width, int height) {}
    width = getPreferredWidth();
    height = super.getPreferredHeight ();
    Super.Layout (width, height);
    uses the features available to the superclass
    Once the width and height defined
    super.setExtent (width, height);
    use the functionality of the super class setExtent
    Once the width and height defined
    }
        
    {} public void paint (Graphics graphics)
            
    graphics.setBackgroundColor (Color.LIGHTBLUE);
    Super.Paint (Graphics);
    }

    }

    width = getPreferredWidth() inside the layout is the main problem. With this line you ignore Manager parent giving your text box the width of your choice (Integer.MAX_VALUE > 1) and tell him «no, I'll work in this width largely only» If you want to limit the width of the gadget, limit the width of the OneLineTextField with

    protected void sublayout(int width, int height) {
      super.sublayout(Math.min(width, this.width), height);
    }
    

    Of course, private int width should be in OneLineTextField, not CustomEditField. This will allow you to deposit your CustomEditField either. If you want your LIGHT blue background, create the OneLineTextField like this:

    OneLineTextField tweetTextField = new OneLineTextField("", 140, width) {
      protected void paintBackground(Graphics g) {
        int prevBgColor = g.getBackgroundColor();
        g.setBackgroundColor(Color.LIGHTBLUE);
        g.clear();
        g.setBackgroundColor(prevBgColor);
      }
    };
    
  • 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

  • Newbie - editfields put in shape on the screen

    HI all, it seems that it should be simple.

    My class screen extends screen and adds a bunch of EditFields.  How to get the labels to align vertically along the left margin of the screen and the data input fields line up vertically along the right edge of the screen?  Please, look at the default AppointmentItem for what I'm trying to accomplish.

    Thank you, Steve

    There is no stock management that does what you want (if I understand the question).

    Fields of change all take them across the width of the default view; the label takes as much as he needs and the text box takes the rest.

    When your right - justify the text box, how much space you take and what direction should the text fill the input box?

    I think that you might be looking at the date fields on the screen that you mention?

    In any case, it will take you either write your own editing field custom, one of those that exist, patch or extend something upward with a HorizontalFieldManager containing a label separate fiekd and the input field (of the sort that you can justify the two fields independently).

  • catch the dialog box "open field"?

    Hello world

    I have an EditField with a limited number of characters in the line. If the user types an equal number, or more characters, "full field" default dialog box appears. Is it possible to change the text in this dialog box?

    lol but you might use a field without maxchars and implement a control of the length of yourself.

Maybe you are looking for