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

Posts: 21
Registered: ‎08-25-2011
My Device: any
My Carrier: any

tab menu change background color

I have created tab menu, created class extending field, able to change the background color on focus but wants to change background color on event click. 


package mypackage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Ui;

public class TabButton extends Field {
String _label;
Bitmap _image;
static int _height = 25; // according to image size
static int _weight = 100;
int _backgroundColor;
int _focusColor;
// private int _statusBit;

public TabButton(String label,
Bitmap image,
long style) {
this._label = label;
this._image = image;
this._backgroundColor = 0x00cccccc;
this._focusColor = 0x000000;

protected void paint(Graphics graphics) {
Font font = Font.getDefault().derive(Font.BOLD, 8, Ui.UNITS_pt);
graphics.setBackgroundColor(isFocus() ? 0x5594f3 : 0xf7be18);
graphics.setColor(isFocus() ? 0xffffff : 0x000000);

if (_label != null) {
graphics.drawText(_label, 5, 3);
//graphics.setColor(isFocus() ? Color.BLACK : 0xf7be18);

protected void layout(int maxWidth, int maxHeight) {
setExtent(_weight, _height);

public boolean isFocusable() {
return true;

protected void drawFocus(Graphics graphics,
boolean on) {
// Don't draw the default focus

protected void onFocus(int direction) {

protected void onUnfocus() {

protected boolean navigationClick(int status,
int time) {
//_backgroundColor = 0x000000;

return true;

Trusted Contributor
Posts: 151
Registered: ‎06-17-2010
My Device: Curve 8900
My Carrier: Vodafone

Re: tab menu change background color

hi rite2subodh,

Check out this link..

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.
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: tab menu change background color

I'm not sure what you have tried, but in you change the background color and then call invalidate(), the Field should be repainted for you, including the background color.


There is nothing in your current code that will do that though.  At least nothing I could see.


I have a tendency to have a 'selected' state, so a Field can indicate not in focus, in focus or selected.  These all have different background colors.


You will probably find the advanced Fields that you have been referred do have a similar concept, because I think I originally stole that idea from them!