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
Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Custom Field, drawing focus problem

This is the code I used.

if(this.isFocus())
		{						
			g.setColor(Color.BISQUE);			
			g.drawRoundRect(0, 0, 160, 40, 10, 10);	
			g.fillRoundRect(0, 0, 160, 40, 10, 10);
			g.drawBitmap(0, 0, 40, 40, receivedImage, 0, 0);
			g.drawText(receivedText, 50, 5);		
		}

 

What happens now is that the highlight color does Chnage, but so does the text Color. And that makes the text invisible. Any suggestions please

_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Custom Field, drawing focus problem

You need to setColor to your "background" color, drawRoundRect, fillRoundRect, then setColor to your text color and only then drawText. The background color is taken into account by g.clear() only (I wonder why does it exist at all then?)

Don't forget to ask your Graphics object about its color before changing to yours, then, after all is done, change the color back to that previous color. Like this:

int oldColor = g.getColor();
try {
  // your painting code, along with all setColor statements
} finally {
  g.setColor(oldColor);
}

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Custom Field, drawing focus problem

You my, friend are very Smart. It works well Thanks. I have never seen try{ }finally { } before. Why does it work if you don't mind me asking?
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Custom Field, drawing focus problem

try {} finally {} is a standard Java feature, so you can read about it in any Java book out there. Many of those are available for free. For example, the previous version of "Thinking in Java" by Bruce Eckel is available for download from his site - www.mindview.net. I'd heartily recommend having that one in paper form, though, with the code CD.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Highlighted
Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Custom Field, drawing focus problem

Ok thanks. A lot Smiley Very Happy
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.