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: 253
Registered: ‎08-14-2010
My Device: Not Specified

drawing on same X with two diffrent font size balckberry java Graaphics



Could anyone please let me know the way to get right y for drawing two text with diffrent hight to be in the same X line , that looks like a one line of text (using Graphics object)?


Thank you in advance

Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: drawing on same X with two different font size blackberry java Graphics

[ Edited ]

I have never done this, but here are the two options I would try:


1) using this form of drawText

drawText(String aText, int aX, int aY)


Assume you have font A and font B, and font B is bigger.  Then when you do the drawText for the string you are outputting using font A, add the difference in height between the two, to the "ay" part of the drawText.


This uses DrawStyle.TOP by default (review the API), which means the y point you specify is the top left hand corner. 


2) Using this form of drawText

drawText(String aText, int aX, int aY, int aFlags)


Specify the aY position you want to be at the 'bottom', and use DrawStyle.BOT in the aFlag.  So aX and aY will specify the bottom left corner. 


I actually suspect that neither of these options will work 100%.  I think you will need to factor into the 'y' position, the difference in the "descent" of each of the Font.  You should be able to figure this out yourself - look at the API for Font, and especially at getBaseline() and getDescent() methods for Font.