EditField colors

EditField _name = new EditField("Name "+new LabelField("*")
            {
                public void paint(Graphics graphics) {
                    graphics.setColor(Color.RED);
                    graphics.clear();
                    super.paint(graphics);
                }

            }, "", 100, EditField.FIELD_RIGHT);

Hello, I have to add an EditField with the label: name (*), but the label is all black.

You add apples and oranges - 'Name' + LabelField simply returns a string with toString() of the LabelField added to the 'name '. You add not any LabelField for any Manager / screen.

In order to achieve what you want, you can create two zones of labels - one with 'Name', another with a "(*)" and paint the place like you did - followed by the Edit with a label field empty. The main difference between this building and the normal EditField with a label is that this return to the line will not as the 'label', as it does in the EditField. If you don't want word wrap and need a simple line of input, consider the following knowledge base article:

Code example - moving line text entry field

It is easy to modify (using two labels with different colors instead of one, for example) and has other ideas in the comments.

Good luck!

Tags: BlackBerry Developers

Similar Questions

  • How to set the color of foreground to EditField

    Hi all

    I added EditField to display new EditField("About:","",1024,EditField.FILTER_DEFAULT).

    Now I want this editfield foreground color value. But there is not setForegroundColor() as setBackgroundColor() in the EditField class.

    Can someone tell me how to set the color of foreground to EditField?

    I think so

    You can change the foreground color by replacing your method of painting:

    That is to say

    editField = new EditField()
    {
        public void paint(Graphics g)
        {
          g.setColor(Color.GRAY);
          super.paint(g);
        }
    };
    
  • How to set the font color EditField

    Hi guys

    Please help me the EditField setting font color.

    I'm doing a screen context menu custom for the credentials of the user with a white background. The problem is that when I put background color to white effects all items included in cluding edit fields.

    To change the fields, I can not set the color of the font all text contained in them become invisible.

    Thank you

    Well it seems settled now.

    I created a custom class and and overrided the paint method

    public class CustomEditField extends EditField
    {
    private int fontColor = -1;
    ...
    protected void paint(Graphics graphics)
    {
        graphics.setColor(fontColor);
        super.paint(graphics);
    }
    
    }
    

    see you soon

  • EditField drawn with top

    Please, I create a Notepad like application for my blackberry and I would like to create an editfield with lines on it like the one in the picture. I really appreciate your help.

    As mentioned, this is not the standard entry BB method.

    Here is a code to get you going, I just wrote this, it is not tested or compiled.  It may not work.  But you'll get the idea and I'm sure that with the idea that you can operate.

    Update the paint method in the provided article which was the following:

    protected void paint (Graphics g) {}
    Super.Paint (g);
    int prevColor = g.getColor ();
    g.setColor (Color.BLACK);
    g.drawRect (0, 0, getWidth(), getHeight());  draw border
    g.setColor (prevColor);
    }

    to something like this:

    protected void paint (Graphics g) {}
    lineHeight int = this.getFont.getHeight ();
    int lines = this.getHeight () / lineHeight;
    for (int i = 0; i)< lines;="" i++="" )="">
    g.drawLine (0, drawHeight, this.getWidth (), drawHeight);
    drawHeight is drawHeight + this.getFont () .getHeight ();.
    }
    Super.Paint (g);
    int prevColor = g.getColor ();
    g.setColor (Color.BLACK);
    g.drawRect (0, 0, getWidth(), getHeight());  draw border
    g.setColor (prevColor);
    }

    As noted, not tested, not compiled, not really production quality code, but I'm sure you have the idea and can rework it based on yourself...  Let us know how you go with it.

  • Dynamically change the color of a string (part of the) text

    Suppose that consider the string Hello "it's the first Blackberry Application" including the color of the text in black, but a few changes need to change the color of the Blackberry to RED as below

    previous - Hello this is the first Blackberry Application

    After - Hello this is the first Blackberry Application

    I tried with split the text into several fields and change the color but I need single solution for Richtextfield / EditField / text box.

    plese give me some suggestions...

    Thanks in advance

    Only ActiveRichTextField will do this for you.

    You define regions, join fonts and/or attributes to the regions, including the background and foreground colors.

  • 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 Layout

    Hi all...

    I try to crreate a custom editfield

    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.DrawStyle;
    import net.rim.device.api.ui.Field;
    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.Ui;
    import net.rim.device.api.ui.XYEdges;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.component.EditField;
    import net.rim.device.api.ui.decor.Border;
    import net.rim.device.api.ui.decor.BorderFactory;
    
    public class BorderEditField extends EditField {
    
        private Border unFocusBorder = BorderFactory.createBitmapBorder( new XYEdges( 12, 12, 12, 12), Bitmap.getBitmapResource("border.png"));
    
        BorderEditField() {
            super();
        }
    
        BorderEditField(long style) {
            super(style);
        }
    
        BorderEditField(String label, String initialValue) {
            super(label, initialValue);
        }
    
        BorderEditField(String label, String initialValue, int maxNumChars, long style) {
            super(label, initialValue, maxNumChars, style | Field.USE_ALL_WIDTH);
            super.setFont(getTextFont());
            setBorder(unFocusBorder);
        }    
    
        public void paint(Graphics g) {
            g.setColor(Color.BLACK);
            g.drawText(super.getText(), 0, 0, DrawStyle.HCENTER + DrawStyle.ELLIPSIS + DrawStyle.TRUNCATE_BEGINNING, getWidth() - 12);
        }
    
        protected void layout(int width, int height) {
            super.layout(width, height);
        }
    
        private Font getTextFont() {
            FontFamily alphaSerifFamily = null;
            try {
                alphaSerifFamily = FontFamily.forName("bbalpha serif");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Dialog.alert(e.getMessage());
            }
            return alphaSerifFamily.getFont(Font.PLAIN, 18, Ui.UNITS_pt);
        }    
    
    }
    

    When I enter a tank that could show more field would create it as a new line, but the text is always on the 1st line

    the 2nd line was empty...

    How the custom editfield does not display the 2nd line? the 2nd line is an empty text

    the text is only 1st line

    Well I found a way to make it work

    protected void layout(int width, int height) {
            super.setExtent(width, height);
            setExtent( isStyle( USE_ALL_WIDTH ) ? width : getPreferredWidth(), getPreferredHeight() );
        }
    
        public void updateScreen() {
            invalidate();
        }
    

    IM, add to the bordereditfield

    but have to invalidate every time I enter a text.

  • Autosizing EditField

    I worked on an EditField autosize intake according to the paint and the value of MaxSize autour rectangle:

    the following code works fine online:

    EditField EF = new EditField ("",null, 8, EditField.FILTER_REAL_NUMERIC)

    {

    public layout zero (int width, int height)

    {

    int x = getFont ().getAdvance("0") * getMaxSize();

    Super.layout (x, getpreferredheight ());

    setExtent (x, getPreferredHeight ());

    } protected void paint (Graphics g)

    {

    g.setColor (Color.GRAY);

    g.drawRect (0,0,getWidth (), getHeight ());

    g.setColor (Color.BLACK);

    Super.paint (g);

    }

    };

    but when I create a class to extend the EditField, it does not work well (the width is set not right)

    public class SizeableEditField extends EditField

    {

    public SizeableEditField()

    {

    new EditField();

    }

    public SizeableEditField (long style)

    {

    new EditField (style);

    }

    public SizeableEditField (label As String, String initialValue)

    {

    new EditField (label, initialValue);

    }

    public SizeableEditField (String initialValue, label As String, style long ,int maxNumChars)

    {

    new EditField (label, initialValue, maxNumChars, style);

    }

    public layout zero (int width, int height)

    {

    int x = this.getFont (.getAdvance("0")) * this. getMaxSize(); / * get the size of the field in pixels of maxChar * /.

    Super.layout (x,this. getPreferredHeight()); / * layout with this space max in mind * /.

    setExtent (x,this. getPreferredHeight()); / * together extend the scope for manager.

    }

    protected void paint (Graphics g)

    {

    g.setColor (Color.GRAY);

    g.drawRect (0,0,this.getWidth(),. getHeight()); g.setColor (color.

    BLACK); Super.paint (g);

    }

    }

    call with:

    SizeableEditField EF = new SizeableEditField ("",null, 8, EditField.FILTER_REAL_NUMERIC);

    The rectangle is painted, but the size is still full hunting, so it seems that x is not calculated on the right.

    No idea why? My debugger will let me see the results of the Expression, os, it is difficult to understand.

    Thanks for help.

    Concerning

    I actually found the problem:

    I need to call super instead of a new EditField

    It works:

    public class SizeableEditField extends EditField

    {

    public SizeableEditField()

    {

    Super ();

    }

    public SizeableEditField (long style)

    {

    Super (style);

    }

    public SizeableEditField (label As String, String initialValue)

    {

    Super (label, initialValue);

    }

    public SizeableEditField (String initialValue, label As String, style long ,int maxNumChars)

    {

    Super (label, initialValue, maxNumChars, style);

    }

    public layout zero (int width, int height)

    {

    int x = getFont ().getAdvance("0") * getMaxSize(); / * get the size of the field in pixels of maxChar * /.

    Super.layout (x, getpreferredheight ()); / * layout with this space max in mind * /.

    this.setExtent (x, getPreferredHeight ()); / * together extend the scope for manager.

    }

    protected void paint (Graphics g)

    {

    g.setColor (Color.GRAY);

    g.drawRect (0,0,this.getWidth(),. getHeight()); g.setColor (color.

    BLACK); Super.paint (g);

    }

    }

  • EditField - cursor stuck in the field

    Hello

    I have an EditField which changes color on onFocus and onUnfocus.  What is strange, is that the slider 'stuck' in the EditField whenever I move (using the trackball) in the field.  I am not able to move out of the EditField until I hit the ESC key.

    Anyone know why this is the case?

    I don't think that it has nothing to do with the definition of the properties available to the field, as all my EditFields behave this way when their "onFocus" and "onUnfocus" attributes are defined.

    (Code pasted below)

    EditField searchtextbox = new EditField(Field.FIELD_VCENTER) {
        public void layout(int width, int height) {
                super.layout(width, height);
                setExtent(250, 25);
                }
    
        public void onFocus(int direction) {
                Background activebgclr = BackgroundFactory
                    .createSolidBackground(Color.WHITE);
                setBackground(activebgclr);
                invalidate();
                select(true);
                }
    
        public void onUnfocus() {
                super.onUnfocus();
                Background inactivebgclr = BackgroundFactory
                        .createSolidBackground(Color.GRAY);
                setBackground(inactivebgclr);
                invalidate();
                }
    };
    

    When the focus is passed to the EditField, you use

    Select (true);

    This puts the ground in "selection mode, more usually used to select pieces of etxt for operations of cut and paste or copy.

    Delete this line and I think that things will work as expected.

  • 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

  • Cursor/Caret appearing does not in EditField?

    I have an EditField which cursor/insertion sign does not appear.  What Miss me?  Here is my code (and I use 4.5.0 and SIM 8300):

    myEditField = new EditField( "", "", 7, Field.EDITABLE | Field.FIELD_LEFT ){
    
    // inner class method to set field size (setExtent)
    public void layout( int width, int height ) {
      int maxFontWidth = getFont().getAdvance( "W" );
      int fieldSize = myEditField.getMaxSize();
      int newWidth = maxFontWidth * fieldSize;
      setExtent( newWidth, getPreferredHeight() );
    }
    
    // inner class methods to handle changes onFocus/onUnfocus
    public void onFocus( int direction ) {
      super.onFocus( direction );
      invalidate();
    }
    
    public void onUnfocus() {
      super.onUnfocus();
      invalidate();
    }
    
    // inner class method to set text/background colors
    public void paint( Graphics g ) {
      if (myEditField.isFocus()) {
        g.setBackgroundColor( Color.LIGHTGREY );
      } else {
        g.setBackgroundColor( Color.WHITE );
      }
      g.fillRect( 0, 0, getWidth(), getHeight() );
      g.setColor( Color.NAVY );
      g.clear();
      g.drawText( myEditField.getText(), 0, 0 );
      super.paint( g );
    }
    
    }; // end inner class overrides
    

    Try this.  Sorry do not know what I changed to your code at random is went through she change things that did not look right.  However, the 'trick' is the drawFocus.

    In any case, I need to real work, please review, compare, test etc and see how you go.

    myEditField = new EditField( "Label", "Text", 7, Field.EDITABLE | Field.FIELD_LEFT ){
    
      boolean _drawFocus = false;
    
    // inner class method to set field size (setExtent)
    public void layout( int width, int height ) {
      int maxFontWidth = getFont().getAdvance( "W" );
      int fieldSize = this.getMaxSize() + this.getLabel().length();
      int newWidth = maxFontWidth * fieldSize;
      super.layout( newWidth, height );
    }
    
    // inner class methods to handle changes onFocus/onUnfocus
    protected void onFocus( int direction ) {
      super.onFocus( direction );
      invalidate();
    }
    
    protected void onUnfocus() {
      super.onUnfocus();
      invalidate();
    }
    
    protected void drawFocus(Graphics graphics,
                             boolean on) {
      _drawFocus = on;
      super.drawFocus(graphics, on);
      _drawFocus = false;
    }
    
    // inner class method to set text/background colors
    public void paint( Graphics g ) {
      if ( _drawFocus ) {
        super.paint(g);
        return;
      }
      int currCol = g.getColor();
      if (this.isFocus()) {
        g.setBackgroundColor( Color.LIGHTGREY );
      } else {
        g.setBackgroundColor( Color.WHITE );
      }
      g.fillRect( 0, 0, getWidth(), getHeight() );
      g.clear();
      g.setColor( Color.NAVY );
      super.paint( g );
      g.setColor(currCol);
    }
    
    }; // end inner class overrides
    
  • 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

  • How to change the width of editfield in blackberry java

    Hi, blackberry has,

    I want to change the width of editfield... can someone tell me how I can do

    Hi Ludovic,.

    use TableLayoutManager and adjust the width of the field (based on no. added columns) for your screen.

    I don't get your condition, but if you want to insert fields so that it will adjust the space then use RoundedPanel and you can add a tablelayoutmanager to this Panel.

    /*
     * RoundedPanel.java
     *
     * © , 2003-2008
     * Confidential and proprietary.
     */
    
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    import net.rim.device.api.system.Display;
    
    /**
     *
     */
    public class RoundedPanel extends VerticalFieldManager {
        private int _heightBtmIncr = 0;
        private int color = Color.WHITE;
        private String str = null;
    
        public RoundedPanel() {
            super(Manager.VERTICAL_SCROLL);
        }
    
        public RoundedPanel(int heightBtmIncr) {
            super(Manager.VERTICAL_SCROLL);
            _heightBtmIncr = heightBtmIncr;
        }
    
        public RoundedPanel(int color , String str) {
    
            super(Manager.VERTICAL_SCROLL);
            this.str = str;
            this.color = color;
        }
    
        public void paint(Graphics g) {
            g.setBackgroundColor(Color.LIGHTGREY);
            int initialColor = g.getColor();
            g.setColor(Color.LIGHTGREY);
            g.fillRect(0, 0, this.getPreferredWidth(), this.getHeight());
            g.setColor(color);
            g.fillRoundRect(3, 3, this.getPreferredWidth() - 6, this.getHeight() - 6, 17, 17);
            g.setColor(Color.DARKGRAY);
            g.drawRoundRect(3, 3, this.getPreferredWidth() - 6, this.getHeight() - 6, 17, 17);
            g.setColor(initialColor);
            super.paint(g);
        }
    
        public void sublayout(int maxWidth, int maxHeight) {
            super.sublayout(maxWidth, Integer.MAX_VALUE);
            int fieldCount = getFieldCount();
            int x = 12;
            int y = 10;
            Field child = null;
    
            for (int i = 0; i < fieldCount; i++) {
                child = this.getField(i);
                setPositionChild(child, x, y);
                layoutChild(child, getFieldWidth(child), Integer.MAX_VALUE);
                int childHeight = getFieldHeight(child);
                y = y + childHeight;
            }
    
            this.setExtent(getPreferredWidth(), Math.max(y, getPreferredHeight()));
            setVirtualExtent(getPreferredWidth(), Math.max(y, getPreferredHeight()));
        }                  
    
        private int getFieldWidth(Field f) {
            return Math.min(Math.max(Math.max(f.getContentWidth(), f.getWidth()), f.getPreferredWidth()), this.getPreferredWidth() - 12);
        }
    
        private int getFieldHeight(Field f) {
            return Math.max(Math.max(f.getContentHeight(), f.getHeight()), f.getPreferredHeight());
        }
    
        public int getPreferredWidth() {
            return Display.getWidth();
        }
    
        public int getPreferredHeight() {
            int height = 6;
            int iNumFields = getFieldCount();
            for (int i = 0; i < iNumFields; i++) {
                height += getFieldHeight(getField(i));
            }
    
            return height + _heightBtmIncr + 6;
        }
    
        protected boolean keyDown( int keycode, int status ) {
            invalidate();
    
            return super.keyDown( keycode, status );
        }
    
        protected boolean navigationMovement( int dx, int dy, int status, int time ) {
            invalidate();
    
            return super.navigationMovement( dx, dy, status, time );
        }
    
        protected int moveFocus(int amount, int status, int time) {
            invalidate();
    
            return super.moveFocus(amount, status, time);
        }
    }
    

    Thank you & best regards

    pp

  • 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.

  • Change the color of the text on the button click

    Hi, how I would change the text with color while the application is running?

    For example, when the user clicks a button, how can I change the color of the editfield with already inserted text?

    I realize that I could add the editifled with different colors, but I was wondering if there is a way to do this without adding new editfield - like refreshing the editfield with different text color.

    Help is very appreciated!

    First, create your own custom class that extends EditField.

    It can be as simple as this:

    public class MyEditField extends EditField {
      private int _color = Color.BLACK;
    
      public void setFontColor(int color) {
        _color = color;
        invalidate();
      }
    
      protected void paint(Graphics g) {
        int prevColor = g.getColor();
        g.setColor(_color);
        super.paint(g);
        g.setColor(prevColor);
      }
    }
    

    Once you have this class, you can use it like this:

    final MyEditField textEntryArea = new MyEditField(...); // any EditField constructor can be used
    
    ...
    FieldChangeListener buttonListener = new FieldChangeListener() {
      public void fieldChanged(Field field, int context) {
        if (field == setToRedButton) {
          textEntryArea.setFontColor(Color.RED);
        } else if (field == setToBlueButton) {
          textEntryArea.setFontColor(Color.BLUE);
        }
        // etc.
      }
    };
    ...
    setToRedButton.setChangeListener(buttonListener);
    setToBlueButton.setChangeListener(buttonListener);
    ...
    

    Edit: fixed a few typos.

Maybe you are looking for

  • Satellite C660 - 19G does not start

    Hello A few years back I bought this laptop for my girlfriend who decided finally to use internet at home. Since day 1, this laptop had problem when start remaining mostly on black screen, with just the noise fan and battery and subsequently leads to

  • App Store not opening

    I have a macbook mid 2012 Pro version of OS X El Capitan current 10.11.1 that the app store is showing an update is available, but I can't get the app store to open, let alone to update!  All I see is a wheel that turns in the top left corner near th

  • FTP file transfer

    Hi all I'm trying to transfer a file from my RIO 9074 on my local machine. I have attached the vi that I use. The problem is that even though I can read all the files inside the RIO, the FTP GET multiple just Files.vi transfers the file to the top of

  • I can't connect to windows user accounts

    I'm unable to access the prompt or my own user account on my Acer Aspire One net book. When I enter my password, the computer begins to open a session (the message "loading your personal settings... ("appears under my account user name) but then it c

  • SPA2102: Install the latest recommended firmware

    Important to keep up-to-date with the latest versions of firmware? I upgraded to 5.2.5 6/09.  I remember having to perform additional upgrades through a few versions to get current. I noticed that since then there have been 5.3.6 and now 5.2.10 http: