开发者

how can the color of the lablefield be changed?

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.

h开发者_开发问答ow 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.


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);
    }
}


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.


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);
        }
    };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜