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
kiran_b
Posts: 260
Registered: ‎10-27-2010
My Device: 8520
Accepted Solution

Editfield + BitmapField in a horizontalfield manager

[ Edited ]

Hi,

 

 I am using below code to show an Edit field and Bitmap in a horizontal field manager but i am getting illegal state exception..

 If i add BitmapField first and then edit field it's working fine but i need Editifield first and then BitmapField

here below is my code....

  Bitmap bg = Bitmap.getBitmapResource("twenty.png");
  locations = new BitmapField(bg,bg,"Locations");
  EditField table=new EditField("Ticket No : ","",5,EditField.FILTER_NUMERIC)
         {
                private int iRectX = getFont().getAdvance(getLabel());
                private int iRectWidth = Display.getWidth() - iRectX - 4;
                public void paint(Graphics g)
                 {
                            g.setColor(0x000000);
                            g.drawRect(iRectX, 0, 170, 18);
                            super.paint(g);
                }
         };

  HorizontalFieldManager hfm=new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
  hfm.add(locations);
  hfm.add(table);
  add(hfm);
 

 I already tried by taking two horizontal fields to add edit field in one and image in another manager and added these two managers into vertical field but no luck..

 

 I tried table layout also..

Please use plain text.
Developer
simon_hain
Posts: 15,873
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Editfield + BitmapField in a horizontalfield manager

editfields use all available width.
you can overwrite getPreferredWidth or use a custom layout:
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
kiran_b
Posts: 260
Registered: ‎10-27-2010
My Device: 8520

Re: Editfield + BitmapField in a horizontalfield manager

By using below code my issue is solved...

   

public int getPreferredWidth() {
                    return Display.getWidth() ;
}

protected void layout(int width, int height) {
    width = Math.min(getPreferredWidth(), width);
    super.layout(width-85, height);
}

 

Thanks simon for your reply....

Please use plain text.