10-09-2010 11:26 PM
I am trying to change the background color of a labelfield after the user selects it. All of the examples are for when you are first creating the field. How do I change the background color of only the selected fied after its selection? Thanks
Joe
10-10-2010 01:48 AM
Do what whatever code/tutorial/etc. says at whatever point the text changes and invalidate the field.
10-10-2010 10:16 AM
Can you give an example? All of the examples involve creating a new labelfield.
Thanks
10-10-2010 04:03 PM
What example do you have for creating it? Do you have code for when the text changes.
10-10-2010 10:09 PM
Here is the example I have in setting the labelfield color upon its creation:
LabelField theLabel = new LabelField(anIDF, Field.FOCUSABLE) {
public void paint(Graphics g) {
g.setBackgroundColor(Color.WHITE);
super.paint(g);
}
};
I need to change the background and font colors of the field some time after it has been created. Any examples would be appreciated. Thanks.
Joe
10-10-2010 10:54 PM
tab1 = new LabelField("label one ", LabelField.FOCUSABLE){
boolean flag = false;
public void paint(Graphics g){
g.setBackgroundColor( Color.WHITE );
g.clear();
g.setColor(0x3D9140);
if(!flag)
g.setColor(Color.BLACK);
else
g.setColor(Color.WHITE);
super.paint(g);
}
public void onFocus(int direction) {
flag = true;
super.onFocus(direction);
this.invalidate();
}
public void onUnfocus() {
flag = false;
super.onUnfocus();
this.invalidate();
}
};
BTW, it is better for you to use "search" at first. You will find this easily if u do that.
10-11-2010 04:57 AM
well i was also facing the same problem.
class FCLabelFieldTabs extends LabelField {
long style;
public FCLabelFieldTabs(Object text, long style) {
super(text, style);
this.style = style;
}
private int mFontColor = -1;
public void setFontColor(int fontColor) {
mFontColor = fontColor;
}
public void setHighlightColor(int backgroundColor){
this.bgColour=backgroundColor;
}
boolean _inFocus = false;
private int bgColour;
public void onFocus(int direction) {
_inFocus = true;
super.onFocus(direction);
this.invalidate();
}
public void onUnfocus() {
_inFocus = false;
super.onUnfocus();
this.invalidate();
this.style = LabelField.NON_FOCUSABLE;
}
public void paintBackground(int bgColour)
{
this.bgColour = bgColour;
invalidate();
//int color = graphics.getBackgroundColor();
//graphics.setBackgroundColor(Color.DARKORANGE); // some color here
//graphics.clear();
//graphics.setBackgroundColor(Color.DARKORANGE);
}
protected boolean navigationClick(int status,int time)
{
// write your code on click
return true;
}
protected void paint(Graphics graphics) {
if (-1 != mFontColor)
{
graphics.setColor(mFontColor);
if ( _inFocus) {
graphics.setBackgroundColor( 0xfe8100 );//ORANGE COLOR ON GETTING FOCUS
graphics.drawRect(0, 0, getWidth(), getHeight());
}
graphics.clear();
super.paint(graphics);
}
}
}
this is the customlabelfield
and then again on focus_GAINED of the label
iam calling onFocus
may be this helps u