tags:

views:

35

answers:

3

Hi, I am trying to set background color of the label and when I override the paint menthod of the LabelField Class it sets the background color where text gets displayed it leaves the rest of the column.

how can we change the background color of the lable where even text is not there.

the text is coming from database and we have fixed column width.

Thanks in advance.

+1  A: 

This is a common problem with UI in Blackberry. You need to subclass the label and set the color before paint:

public class Custom extends LabelField {
    protected void paint(Graphics graphics) {
        graphics.setColor(Color.BLACK);
        super.paint(graphics);
    }
}
Reflog
You don't need to subclass it. You can do the paint function on the instantiated object.
paullb
@Reflog,@paullb i think he wants to change the background color of lablefield not the text color. For that refer this thread http://stackoverflow.com/questions/3014109/how-to-change-label-color-in-blackberry-using-eclipse/3014400#3014400
Vivart
A: 

You can implement the paint on the instantiated version of the field. This way you avoid the overhead of making your own custom class.

ButtonField myButton = new ButtonField("button")  {
    protected void paint(Graphics graphics) {
         graphics.setColor(Color.BLACK);
            super.paint(graphics);
        }
    };
paullb
+1  A: 

Hi,There are two things, you can change the background color of the text and text area.I hope you are opting for setting the background color of the text area.

LabelField lb = new LabelField("Label")  {

//Setting backgroundColor of the Text

    protected void paint(Graphics graphics) {
             graphics.setColor(Color.LAVENDAR);
                super.paint(graphics);
            }
        };

//Setting backgroundColor of the TextArea(Note the Difference)

     protected void paintBackground(Graphics graphics) {
             graphics.setBackgroundColor(Color.GOLDENROD);
             graphics.clear();
            }
        };

I hope this codes will be helpful.

Rakesh