3

I am preparing for a new app, just want to create a TextField.

I have to provide functionality to select a portion of text and change its color. For example: hello, I am blackberry developer. Now I want to change the font color of blackberry developer at runtime.

Is it possible in EditField or BasicEditField or RichTextField in any one??? Thanxx in advance!:)

CRUSADER
  • 5,486
  • 3
  • 28
  • 64
Sam-In-TechValens
  • 2,501
  • 4
  • 34
  • 67
  • It is impossible with neither *stock* `BasicEditField` nor with *stock* `EditField`. As far as I remember, it is possible with `RichTextField`. – tonymontana Apr 27 '12 at 15:33

1 Answers1

1
LabelField labelField2 = new LabelField("hello, I am blackberry developer",Field.FOCUSABLE){

        boolean _inFocus = false;
        public void onFocus(int direction) {
            _inFocus = true;
            this.invalidate();
        }
        public void onUnfocus() {
            _inFocus = false;
            this.invalidate();
        }
        protected void paint(Graphics graphics) {
             if(_inFocus){
                 graphics.setColor(Color.BLUE);
             }else{
                 graphics.setColor(Color.RED);
         }
          super.paint(graphics);
       }
       protected void drawFocus(Graphics g, boolean on) {
      }
    };

Enjoy...

Suresh Kerai
  • 891
  • 1
  • 6
  • 20
  • I think it will change the color for whole string, `hello, I am blackberry developer`. But the question asks for how to set font color of the selected text only, e.g. changing the color of `blackberry developer`, not all the text. – Rupak Apr 27 '12 at 12:09
  • create two lableField and set on HorizontalFieldManager. One LabelField is focusable and one LabelField is not focusable.Now what ever focusable lableField it will change color and if there are not focusable it will remain same. Other wise set your color logic in to paint method. – Suresh Kerai Apr 27 '12 at 12:49
  • thanx for giving your time but I need to make it clear that I am working with an edit field not a label field, lets say i am writing a mail in my applicaition and at that time i want to select 2 words and wants to change its color. Now i think we can not use label field for run time editing or entering data in fields. please provide sugggestions. – Sam-In-TechValens Apr 27 '12 at 14:52
  • This link May be helpfull. http://supportforums.blackberry.com/t5/Java-Development/Format-text-in-a-RichTextField/ta-p/445038 – Suresh Kerai May 03 '12 at 10:15