Tutorials Blackberry How to make mobile application portable for multiple devices in Blackberry

How to make mobile application portable for multiple devices in Blackberry

There are various UI techniques the developers need to follow and various concerns need to concentrate on. The major among all is device resolution. As we all know, in blackberry market the mass of the JDE versions are still 4.5. When we target an application for blackberry smartphone we cant leave JDE4.5 version devices.

Basically if we consider the devices like pearl we have less screen width as compared to other models like torch, storm or curve.Consider a business application where we have a choice field or a label field which need to fit in multiple screen resolution device. How smart are you to handle this?.Here we need to take font into consideration and few set of logic need to change in you customized choice field. The font need to calculate dynamically as per the screen with. Here is a code snapshot which will guide you to customize this for objectChoiceField.

protected void paint(Graphics graphics) {
  Resolutions r = new Resolutions();
  Font labelFont = r.getFont();
  Font font = r.getFont();
  int width = r.CustomRowWidth - 3;

  int calcWidth = 0;
   calcWidth = labelFont.getAdvance(label)+maxWidth(font);
   int height = font.getHeight();   
   height = height - 2;
   FontFamily fontFamily = null;
   fontFamily = Font.getDefault().getFontFamily();
   font = fontFamily.getFont(Font.PLAIN,height);

  if (-1 != mFontColor)


Here maxWith() method calculates the maximum length among all the choices available in choiceField.

 public int maxWidth(Font font){
  int max = -1;
  for(int i =0;i<this.getSize();i++){
   String s = (String)this.getChoice(i);
   int width =font.getAdvance(s);
    max = width;
  return max;
Newest Most Voted
Inline Feedbacks
View all comments
11 years ago

can u post the complete code . when i try to use it is not working

10 years ago
Reply to  Anonymous

Thanks for referring my blog. The above code is just a trick to make it portable across the devices of different resolutions. I haven’t pasted the complete code here.

Previous Post
Blackberry Tutorials

Custom LabelField in Blackberry

Next Post

How does double Buffering works in J2ME ?

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All