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.
Asked
Active
Viewed 765 times
1

CRUSADER
- 5,486
- 3
- 28
- 64

chaitu2408
- 97
- 5
3 Answers
1
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 extendsHorizontalFieldManager
- Add 2 fields to this, a
LabelField
for the label and anEditField
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.

donturner
- 17,867
- 8
- 59
- 81
0
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

BBdev
- 4,898
- 2
- 31
- 45
-
1Won't this change both the label and the text content? The question is how to change the color of just the label. – Michael Donohue Nov 19 '11 at 21:00
-2
EditField _textBox = new EditField("Subject","Some text")
{
public void paint(Graphics g)
{
getManager().invalidate();
g.setColor(_color);
super.paint(g);
}
}

V.J.
- 9,492
- 4
- 33
- 49
-
1Won't this change both the label and the text content? The question is how to change the color of just the label. – Michael Donohue Nov 19 '11 at 21:00
-
2Why invalidate the Field's Manager? It is not up to the Field to decide whether its Manager's Fields are invalid – donturner Nov 20 '11 at 02:37
-
I don't have the answer, otherwise I would have posted it already. – Michael Donohue Nov 23 '11 at 05:01