3

i am using a bitmap field that contains a small image.

when focus comes on that image then blue color of the focus does not appears,how can i set the focus width and height

my code::

contract_image_field = new BitmapField(contract_image,Field.FOCUSABLE)
 {
       public void getFocusRect(XYRect rect) 
      {
       rect.width=0;
       rect.height=0;
       //super.getFocusRect(rect);
      }
       protected void onFocus(int direction) 
       {
        myScreen.this.invalidate();
      super.onFocus(direction);
     }
       protected void onUnfocus() 
       {
        myScreen.this.invalidate();
      super.onUnfocus();
     }
      };
      contract_image_field.setBitmap(contract_image);

this is the way how i work with image field,

though my image is clickable but i cant see that blue color(i want that please help!!!)

changing values of width and height in getFocusRect does not even solves the problem

Swati
  • 2,870
  • 7
  • 45
  • 87

3 Answers3

4

You can also avoid increasing the field extent; using the following code:

BitmapField bitmapField = new BitmapField(bitmap, BitmapField.FOCUSABLE)
{
     protected void drawFocus(Graphics graphics, boolean on) 
     {
          setSpace(5, 5);
          super.drawFocus(graphics, on);
     }       
};
Ashraf Bashir
  • 9,686
  • 15
  • 57
  • 82
3

actually focus is there but you can't see because focus region is the same as the field's entire extent. if you want to see focus rect increase the field extent.

BitmapField  bitmapField = new BitmapField(bitmap,Field.FOCUSABLE){
            protected void layout(int width, int height) {
                setExtent(bitmap.getWidth()+10, bitmap.getHeight()+10);
            }

        };
Vivart
  • 14,900
  • 6
  • 36
  • 74
  • Thank u so much Vivart for solving my problem – Swati Feb 23 '10 at 10:36
  • This will only put the blue focusing area in right side and down side of the bitmap, but not on left side and top side. So, I think a better solution is to use setSpace in the drawFocus method, I'll post the code for this. – Ashraf Bashir Mar 08 '10 at 10:34
0

Ashraf's suggestion is correct, only I would try to avoid setting the 'space' on every drawFocus call.

just call setSpace(int, int) member once on the bitmapField in question.

humbleSapiens
  • 163
  • 11