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

Regular Contributor
Posts: 68
Registered: ‎08-16-2011
My Device: TMOBILE 8900
My Carrier: developer

runtime alignment of text for various device


i have to download a file and set those texts of file in screen for various device.and i dont want to use setmargin feature for that beacause there are severel number of  device including touch and non touch.i want those lines to set in device screen according to resolution,height and widths.is it possible?please provide solution.....!

Posts: 206
Registered: ‎02-22-2011
My Device: BB TORCH & 9800
My Carrier: idea

Re: runtime alignment of text for various device

yes its possible.
for exapmle if you want to display the text at center of the screen in any device do like this

take any device width and your text width

Display.getWidth() - retrieves the screen width

// if you added the text to labelField then
labelfield.getFont().getAdvance(lblField.getText()) - for text width

// If you are drawing the text in paint then
graphics.getFont().getAdvance(your text) - for text width


// >> operator used for shifting each 1-bit to right i.e., dividing by 2

int result = (Display.getWidth() - labelfield.getFont().getAdvance(lblField.getText()) ) >>1

here result value gives the integer value for horizontally center.

so above steps are for displaying the text in horizontally center.

you take the Display.getHeight() to retrieve any device height and do the calculations.

for proper height like above you can take getHeight() method.

* Give kudos when you like it
* Mark it as a solution if it fixes your issue