chaitu2408
chaitu2408

Reputation: 97

Change color of only the label for TextField in Blackberry

I am trying to a add a TextField. I am using EditField _textBox = new EditField("Subject", "Some text"); for creating a textbox with label as Subject. I want to change the color of only the label(Subject) of the textbox.

Upvotes: 1

Views: 766

Answers (3)

donturner
donturner

Reputation: 19146

You're going to need a custom field to do this because it is not possible to change the colour of the EditField's label, even if you override EditField.paint().

My suggestion is:

  • Create a class (e.g. CustomEditField) which extends HorizontalFieldManager
  • Add 2 fields to this, a LabelField for the label and an EditField for the editable text
  • Override the paint() method for the LabelField to set the colour which you want.

Here's the code:

import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.Graphics;

public class CustomEditField extends HorizontalFieldManager{

    private static final int COLOR = 0x00FF0000; //colour for the label 
    private LabelField labelField; //for the label
    private EditField editField; //for the editable text

    public CustomEditField(String label, String initialValue){

        labelField = new LabelField(label){

            public void paint(Graphics g){

            g.setColor(COLOR);
                super.paint(g);
            }

        };

        editField = new EditField("", initialValue); //set the label text to an empty string

        add(labelField);
        add(editField);     
    }   
}

Of course, you're still going to need to add in your methods to set and get the text from your EditField, and any other specific methods which you need from EditField, but as a proof of concept this works.

Upvotes: 1

BBdev
BBdev

Reputation: 4942

You can Override the paint() method and can call the setColor(int RGB) method to give the color you want may be this will help

Upvotes: 0

V.J.
V.J.

Reputation: 9580

EditField _textBox = new EditField("Subject","Some text")
{
public void paint(Graphics g) 
{
        getManager().invalidate();
        g.setColor(_color);
        super.paint(g);
}
}

Upvotes: -2

Related Questions