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
Posts: 30
Registered: ‎06-01-2009
My Device: 9000 Bold
Accepted Solution

Creating a menu with rollover images button

[ Edited ]

Hi,

 

I'm building a menu with rollover images buttons. It consists in putting 5 buttons one under the other.

 

I built a class with a background image that changes between focus and non-focus state, to make the rollover. To enable focusable state, I simply added a transparent gif (width setSpace to cover all the background surface).

 

The focus/unfocus works great, but when i reach the top button or the bottom button, the transparent gif and its space become white...

 

 

 

 

 

We can see the background on the right of the white square...

 

 

Here is the class of the button :

 

 

 

 

 

package com.blabla.ae.component;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;

import com.blabla.ae.AE_Csts;

public class CustomImageButton extends HorizontalFieldManager
{

private Bitmap offBitmap;
private Bitmap onBitmap;
private Bitmap currentBitmap;

private Bitmap noBitmap;
private BitmapField noImgBitmapField;



private int index = 0;

private int imageWidth;
private int imageHeight;

public CustomImageButton()
{

}

public CustomImageButton(String _imageOff, String _imageOn, int _index)
{
super(HorizontalFieldManager.USE_ALL_WIDTH);
try
{

index = _index;
offBitmap = Bitmap.getBitmapResource(_imageOff);
onBitmap = Bitmap.getBitmapResource(_imageOn);
currentBitmap = offBitmap;

noBitmap = Bitmap.getBitmapResource("pix.gif");
noImgBitmapField = new BitmapField(noBitmap)
{
public boolean isFocusable()
{
return true;
}


protected void drawFocus(Graphics _g, boolean on)
{

}
protected void paint(Graphics _g)
{
System.out.println("paint no bitmapfield");
_g.setBackgroundColor(0x00ff0000);
_g.setGlobalAlpha(0);
_g.clear();
super.paint(_g);
}
};
this.add(noImgBitmapField);

imageHeight = onBitmap.getHeight();
imageWidth = onBitmap.getWidth();
noImgBitmapField.setSpace(imageWidth/2-1, imageHeight/2);
//this.add(content);
}
catch(Exception e)
{
System.out.println("erreur CR = " + e.getMessage());
}

}

protected boolean navigationClick(int status, int time)
{
fieldChangeNotify(1);
return true;
}

protected void onFocus(int direction)
{
System.out.println("onfocus");
super.onFocus(direction);
currentBitmap = onBitmap;
invalidate();
}

protected void onUnfocus()
{
System.out.println("onUNfocus");
super.onUnfocus();
currentBitmap = offBitmap;
invalidate();
}

public boolean isFocusable()
{
return true;
}

protected void drawFocus(Graphics graphics, boolean on)
{

}

protected void fieldChangeNotify(int context)
{
try
{
this.getChangeListener().fieldChanged(this, context);
}
catch (Exception e)
{}
}

protected void paint(Graphics graphics)
{
try
{
graphics.drawBitmap(0, 0, imageWidth, imageHeight, currentBitmap, 0, 0);
graphics.setColor(AE_Csts.COL_BLACK);
super.paint(graphics);
}
catch(Exception e)
{
}
}

public int getItemIndex()
{
return index;
}



}

 

Any idea of what is wrong in my code? 

 

 Thanks!
Message Edited by sheepk on 08-05-2009 07:34 PM
Message Edited by sheepk on 08-05-2009 08:43 PM
Developer
Posts: 30
Registered: ‎06-01-2009
My Device: 9000 Bold

Re: Creating a menu with rollover images button

Ok I resolved that issue with the help of this thread :

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=39506

 

Thanks