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
redpath
Posts: 62
Registered: ‎07-29-2008
My Device: Not Specified
Accepted Solution

MIDP2.0 ItemImage and ItemString Text to right on same line?

Is there some trick to this on the Blackberry Pearl.

I want an Image and then text to the right of the image as the first line

in a configuration form. I am trying to support the Pearl 8110 and so on

It only puts the Image on a line by itself no matter what layout combos

I use

 

        try {
            Image image=Toolkit.createImage("/tivoli.png");
            ImageItem it=new ImageItem("",image,Item.LAYOUT_2|Item.LAYOUT_SHRINK|Item.LAYOUT_LEFT,"");
            sf.append(it);
        } catch (Exception e) {
        }
StringItem si = new StringItem("","a"+tbsmNLS.get("label-conf")+"\n");
si.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
si.setLayout(Item.LAYOUT_2);

 

The WTK emulator works fine for every combo I seem to think would work

and I am getting tired of building and trying to test on the

real device to get it to work. The image and string very easilly can fit on a row.

 

Also this works fine a Nokia E60

 

 

 

Developer
redpath
Posts: 62
Registered: ‎07-29-2008
My Device: Not Specified

Re: MIDP2.0 ItemImage and ItemString Text to right on same line?

Just gave in and wrote my own label

 

package com.ibm.tivoli.midp;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ImageString extends CustomItem {
   Image img;
   String st;
   Font font;


   public ImageString(Image image, String title){
       super("");
       font=Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
       img = image;
       st =  title;
   }

   protected int getMinContentHeight() {
      return img.getHeight();
   }

   protected int getMinContentWidth() {
     return img.getWidth()+font.stringWidth(st)+5;
   }

   protected int getPrefContentHeight(int width) {
    return  img.getHeight();
   }

   protected int getPrefContentWidth(int height) {
     return img.getWidth()+font.stringWidth(st)+5;
   }

   protected void paint(Graphics g, int w, int h) {
      g.drawImage(img,0,0,Graphics.LEFT|Graphics.TOP);
      g.setFont(font);
      g.drawString(st,img.getWidth(),img.getHeight()-font.getHeight(),
                   Graphics.LEFT|Graphics.TOP);
   }

   protected boolean traverse(int dir, int viewportWidth, int viewportHeight,
                              int[] visRect_inout) {
       return true;
   }

   protected void sizeChanged(int w, int h){
   }
}