Reputation: 11
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.
Upvotes: 1
Views: 224
Reputation: 15047
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.
Upvotes: 1
Reputation: 4325
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);
}
};
Upvotes: 0
Reputation: 7645
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);
}
}
Upvotes: 1