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

Posts: 1
Registered: ‎07-07-2010
My Device: 9000
My Carrier: abc
Accepted Solution

Focus rectangle



New to blackberry development.I have seen that when I focus on any icon within my application, it gets surrounded by a blue rectangle filling the surrounding portions.


1) Can I change this color to some other ?


2) if a direct change of color is not possible ,Can I place that custom colored rectangle as an image under the icon and write appropriate methods on focus and unfocus?


Suggestions needed on required code to do the same.



Posts: 17,023
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Focus rectangle

welcome to the support forums.


the focus/highlighting is controlled by this method:

 http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/Field.html#drawFocus(net.rim.device.api.ui.Graphics, boolean)


if you want to have a different image on focus you could overwrite drawFocus empty and change the bitmap of a bitmapfield onFocus/onUnFocus.

feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: Focus rectangle

Hi Jack,

Welcome to the forums. Do take a look at the link provided by Simon. There are various ways to manipulate the focus, here's one that's not neccessarily the one you want but you get the idea.



protected void drawFocus(Graphics graphics,boolean on) {

XYRect rect = new XYRect();
graphics.setColor( Color.RED);
graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true);
drawHighlightRegion(graphics, Field.HIGHLIGHT_SELECT, false, rect.x, rect.y, rect.width, rect.height);