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
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

HowTo - Platform agnostic custom ChoiceField painting

If you want to custom paint a ChoiceField (not the popup) but you want your code to work for all platforms this bit of information may help because the ChoiceField is a little convoluted. The ChoiceField.paint(Graphics) method controls when the selection popup opens. I know, right, wth... So that makes custom painting difficult because the Storm likes to paint giant buttons that are easy to click, but get in our way when painting. One way around that would be to call super.paint(Graphics) and the graphics.clear()... but then you lose everything the Manager painted behind it if you choose to have a margin or rounded edges. So with that option off the table you sill have to call super. Pushing a graphics context and setting the gobal alpha to 0 (transparent) before calling graphics.clear() doesn't work either. Finally we come to:

 

Bitmap bitmap = new Bitmap(1,1);

Graphics graphics = new Graphics(bitmap);

super.paint(graphics);

 

This allows the parent class be notified that the selection popup should displayed (bleh), and it doesn't trash up your custom painting becuase the graphics object gets discarded.

 

Cheers,

Please use plain text.
New Developer
coreymitchell81
Posts: 23
Registered: ‎04-15-2009
My Device: Not Specified

Re: HowTo - Platform agnostic custom ChoiceField painting

I can't try this until I get home tonight but it looks like it makes sense.  I tried a similar concept of capturing the existing graphics context, calling super.paint, then reassigning graphics to the previously captured graphics object but it didn't work.  Your idea looks like it will.  Thanks, I'll let you know how I turn out!
Please use plain text.
Developer
dev2011
Posts: 17
Registered: ‎08-14-2009
My Device: Not Specified

Re: HowTo - Platform agnostic custom ChoiceField painting

Thank you very much for this! For the last couple hours, I've been trying to figure out how to make the PopUp appear!

Please use plain text.
New Contributor
damnsmart
Posts: 4
Registered: ‎10-12-2011
My Device: bold
My Carrier: airtel

Re: HowTo - Platform agnostic custom ChoiceField painting

Thanks!!!!

It works like charm :smileyhappy:

Please use plain text.