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
New Contributor
joedvorak
Posts: 8
Registered: ‎10-09-2010
My Device: Curve 8900
My Carrier: AT&T

Changing labelfield background color after selection

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

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Changing labelfield background color after selection

Do what whatever code/tutorial/etc. says at whatever point the text changes and invalidate the field.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
New Contributor
joedvorak
Posts: 8
Registered: ‎10-09-2010
My Device: Curve 8900
My Carrier: AT&T

Re: Changing labelfield background color after selection

Can you give an example? All of the examples involve creating a new labelfield. 

 

Thanks

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Changing labelfield background color after selection

What example do you have for creating it? Do you have code for when the text changes.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
New Contributor
joedvorak
Posts: 8
Registered: ‎10-09-2010
My Device: Curve 8900
My Carrier: AT&T

Re: Changing labelfield background color after selection

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

Please use plain text.
Developer
tiandi79
Posts: 110
Registered: ‎10-22-2009
My Device: 9700
My Carrier: ChinaMobile

Re: Changing labelfield background color after selection

 

    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.

 

Best Regards,
Tiandi
www.tiandiyoyo.com
Please use plain text.
Developer
Nadirfirfire
Posts: 192
Registered: ‎01-12-2010
My Device: Bold
My Carrier: ZAIN

Re: Changing labelfield background color after selection

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

 

Please use plain text.