Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Change labelfield text color

 

_labelField = new LabelField("Email"){
            public void paint(Graphics graphics){
               
                graphics.setColor(Color.WHITE);
                graphics.clear();
                super.paint(graphics);
            }
        };

 Simple but i dont want to do it like that, i want to do it outside paint. say on a button click i want to change _labelfield color to black....

 

Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: Change labelfield text color

Font font = getFont().derive(Font.BOLD);
_labelfield.setFont(font);

found this, to make it bold.but no color
Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: Change labelfield text color

public void paint(Graphics graphics){

graphics.setColor(Color.WHITE);
super.paint(graphics);
}
Developer
Posts: 134
Registered: ‎08-03-2011
My Device: torch, Z10
My Carrier: Vodafone, Airtel

Re: Change labelfield text color

You Have to do Like This.

 

LabelField _labelField;
ButtonField btn;
boolean lblClick;
public MyScreen() {

_labelField = new LabelField("Email"){
public void paint(Graphics graphics){
if(lblClick){
graphics.setColor(Color.WHITE);
graphics.clear();
}
super.paint(graphics);
}
};

btn=new ButtonField();
btn.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
lblClick=true;
invalidate();
}
});

add(_labelField);
add(btn);
}

 

-------------------------------------

Brajesh Sanodiya

 

click to accept solution if it works.

-----------------------------------------------------------------------
"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
-----------------------------------------------------------------------
Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Change labelfield text color

The previous posters are correct to tell you to override paint, the standard LabelField does not allow you to specify the text color.

 

However what I would do is extend LabelField, create say a ColorTextLabelField, and add a 'setTextColor(int colr) method to the Field.  In paint(0 you will code something what has been suggested before to set the graphics color to the text color you want and then call super.paint(.).

 

Then you can reuse ColorTextLabelField whereever you want!