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: 86
Registered: ‎01-09-2009
My Device: Not Specified
Accepted Solution

Custom Field highlighting problem

Hi,

 

I have a custom field   class that extends Field.  the custom class allows  me to put a picture inside the field.  The problem i have is when I give it a click event, it does not highlight.

I have overrided onFocus() onUnfocus() drawFocus() and Paint();

 

i have tried using super.drawFocus() inside drawFocus(), tried using drawHighlightRegion, with HIGHLIGHT_SELECT and with HIGHLIGHT_FOCUS but no luck.

 

does anyone know what i have to do to give it hightlight when user touches the screen or click on it??

 

Developer
Posts: 86
Registered: ‎01-09-2009
My Device: Not Specified

Re: Custom Field highlighting problem

anyone ???

how is the highlighting suppose to work anywayif we extend a class?

Highlighted
Developer
Posts: 46
Registered: ‎07-12-2008
My Device: Not Specified

Re: Custom Field highlighting problem

For custom fields you will most likely need to draw the focus yourself.  I've made some some simple buttons this way.  Just use the graphics object inside drawFocus.

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Custom Field highlighting problem

[ Edited ]

If you are trying to show focus on a bitmap, this can be a special issue. You'll need to provide some extra spacing around the bitmap so that you can indicate focus by painting (for example) a different color background behind the bitmap. If you field extent is the same size as the bitmap, then there is really no way for your focus to show.

 

Another way that I have done this is to paint a rectangle around the extend of the bitmap, using a stiple pattern so that the bit map is highlighted with alternating black & white bars. This gives you a sort-of "dancing ants" focus which retains the original extent of the bitmap field.

 

Here is an example of what I am talking about:

protected void drawFocus(Graphics graphics,boolean on) { if (on){ graphics.setColor(Color.WHITE); graphics.drawRect(0,0,getWidth(),getHeight()); graphics.setColor(Color.BLACK); graphics.setStipple(0xcccccccc); graphics.drawRect(0,0,getWidth(),getHeight()); } }

 

 

Message Edited by RexDoug on 02-06-2009 05:10 PM
Developer
Posts: 86
Registered: ‎01-09-2009
My Device: Not Specified

Re: Custom Field highlighting problem

I have the focus, i change the bitmap to show focus.  But I would like to get the original blackberry BLUE highlighting on focus as we see in the main menu when you click on the screen.

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Custom Field highlighting problem

OK, so like I said in the previous post, you can paint the blue highlight, but your bitmap will then paint over top of the highlight.

 

In order to make the highlight visible, you need to set some padding around the bitmap. In other works, the Field extent must be slightly larger than the bitmap extent.

 

You best bet would have been to extend BitmapField (rather than Field), and use the setSpace() method to set some padding.

 

Failing that, you'll need to adjust the field extent in your subLayout() override.

 

BlackBerry Development Advisor
Posts: 15,693
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Custom Field highlighting problem

The default behaviour of a BitmapField is to highlight transparent regions of the image.  So you also could use an image with a transparent border to achieve this.  Just be sure to use an image format that supports transparent regions (PNG or GIF).
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker