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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
Developer
Posts: 62
Registered: ‎07-14-2008
My Device: Not Specified

Text alignment in drawText()

How can I get my text to be aligned automatically in paint() of my custom field. Here what I've tried and thought it would work, but the text alignment is still top left - it should be VCENTER LEFT. It worked that way with HALIGN_MASK in the CustomButtonField example.

 

protected void paint(Graphics graphics) { if (isFocus()) { graphics.setColor(Color.WHITE); graphics.fillArc(10, 3, _imageHeight, _imageWidth, 0, 360); graphics.setColor(Color.RED); graphics.drawText(_label, 15 + _imageWidth, 0, (int)( getStyle() & DrawStyle.VALIGN_MASK ), getWidth()); } graphics.drawBitmap(10, 3, _imageHeight, _imageWidth, _image, 0, 0); }

 

 

the field is created passing VCENTER style flag:

 

 

_imfItems[index] = new ImageButtonField(bmp, "Item 1", ImageButtonField.USE_ALL_WIDTH | ImageButtonField.VCENTER)

 

 

 

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Text alignment in drawText()

You can use alignment bits (Graphics.HCENTER / VCENTER / TOP / LEFT / etc) when drawing [some things] with the graphics object, however they would be based on the coordinates you specify. If your field height is 10, and you send a y of 0 with VCENTER... it is not going to draw it at 5 because its the center of your field, it would draw at a negative number (say -3 if your font height is 6). Figure out the actual y position and send it to the drawText() method.... y = (int) ((height - fontHeight) * 0.50)
Developer
Posts: 62
Registered: ‎07-14-2008
My Device: Not Specified

Re: Text alignment in drawText()

Thanks Martin for the explanation!

 

Right, that's the way I did it before I looked at the CustomButton example. So I though if drawText accepts style bits as parameters it would also be "smart" enough to do alignment automatically...