Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:41:59+00:00 2026-05-31T17:41:59+00:00

I am trying to change the bitmap of a custom buttonfield on focus. I

  • 0

I am trying to change the bitmap of a custom buttonfield on focus. I have 2 images, one in grey, the other in red, and I wish to swap them when the button is focused.

This code is making the buttons twitch to the right value for a fraction of a second, going from grey to red. When focused it is selcted, and generates an unwanted event. After changing, it goes right back to the original color and the simulator freezes.

Can anyone help us find whats wrong with this code?

My custom buttonField class:

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;

public class ImageNavbarButtonField extends BitmapField{

private Bitmap image;
private boolean isFocused;

public ImageNavbarButtonField(Bitmap image) {
    super(image);
    this.image = image;
}

public boolean isFocusable() {
    return true;
}

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

protected boolean trackwheelClick(int status, int time) {
    fieldChangeNotify(0);
    return true;
}

protected void drawFocus(Graphics graphics, boolean on){} 
public void onFocus(){
        setBitmap(ImageResizer.generateHitBitmap(image));
        invalidate();
 }

 public void onUnfocus(){
         //super.onUnfocus();
         setBitmap(image);
         invalidate();
 }

protected void paint(Graphics graphics) {
    super.paint(graphics);
}

protected boolean keyChar(char character, int status, int time) {
    if(Characters.ENTER == character || Characters.SPACE == character) {
        fieldChangeNotify(0);
        return true;
    }
    return super.keyChar(character, status, time);
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:42:00+00:00Added an answer on May 31, 2026 at 5:42 pm

    try this

    final imagebutton sav_users = new imagebutton("",Field.FOCUSABLE, "normalimage.png","mouseoverimage.png", 0x9cbe95);
    

    imagebutton classs is given below-

    import net.rim.device.api.ui.*;
    import net.rim.device.api.system.*;
    
    public class imagebutton extends Field {
    
    private String _label;
    private int _labelHeight;
    private int _labelWidth;
    private Font _font;
    
    private Bitmap _currentPicture;
    private Bitmap _onPicture; 
    private Bitmap _offPicture; 
    int color;
    
    public imagebutton(String text, long style ,String img, String img_hvr, int color){
        super(style);
    
    
        _offPicture = Bitmap.getBitmapResource(img);
        _onPicture = Bitmap.getBitmapResource(img_hvr);
    
        _font = getFont();
        _label = text;
        _labelHeight = _onPicture.getHeight();  
        _labelWidth = _onPicture.getWidth();
    
        this.color = color;
    
        _currentPicture = _offPicture;
    }
    
    /**
     * @return The text on the button
     */
    String getText(){
        return _label;
    }
    
    /**
     * Field implementation.
     * @see net.rim.device.api.ui.Field#getPreferredHeight()
     */
    public int getPreferredHeight(){
        return _labelHeight;
    }
    
    /**
     * Field implementation.
     * @see net.rim.device.api.ui.Field#getPreferredWidth()
     */
    public int getPreferredWidth(){
        return _labelWidth;
    }
    
    /**
     * Field implementation.  Changes the picture when focus is gained.
     * @see net.rim.device.api.ui.Field#onFocus(int)
     */
    protected void onFocus(int direction) {
        _currentPicture = _onPicture;
        invalidate();
    }
    
    /**
     * Field implementation.  Changes picture back when focus is lost.
     * @see net.rim.device.api.ui.Field#onUnfocus()
     */
    protected void onUnfocus() {
        _currentPicture = _offPicture;
        invalidate();
    }
    
    /**
     * Field implementation.  
     * @see net.rim.device.api.ui.Field#drawFocus(Graphics, boolean)
     */
    protected void drawFocus(Graphics graphics, boolean on) {
        // Do nothing
    }
    
    /**
     * Field implementation.
     * @see net.rim.device.api.ui.Field#layout(int, int)
     */
    protected void layout(int width, int height) {
        setExtent(Math.min( width, getPreferredWidth()), 
        Math.min( height, getPreferredHeight()));
    }
    
    /**
     * Field implementation.
     * @see net.rim.device.api.ui.Field#paint(Graphics)
     */
    protected void paint(Graphics graphics){       
        // First draw the background colour and picture
        graphics.setColor(this.color);
        graphics.fillRect(0, 0, getWidth(), getHeight());
        graphics.drawBitmap(0, 0, getWidth(), getHeight(), _currentPicture, 0, 0);
    
        // Then draw the text
        graphics.setColor(Color.BLACK);
        graphics.setFont(_font);
        graphics.drawText(_label, 4, 2, 
            (int)( getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK ),
            getWidth() - 6 );
    }
    
    /**
     * Overridden so that the Event Dispatch thread can catch this event
     * instead of having it be caught here..
     * @see net.rim.device.api.ui.Field#navigationClick(int, int)
     */
    protected boolean navigationClick(int status, int time){
        fieldChangeNotify(1);
        return true;
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have picturebox with picture cb. PBr1_1.Image = new Bitmap(@Logos\\Images\\cb.png); I'd like to change
In my Form1 I am trying to change around 50 button images as follows:
Im drawing a bitmap at a canvas. Im trying to have this bitmap rotate
I am trying to change the alpha value of a bitmap per pixel in
a newbie question. I'm trying to change an alpha value of a bitmap item
I'm trying to modify my bitmap to change their pixels to a random color.
I'm trying change an input mask for textbox when the the check box has
Am trying to change the button frame according to the orientation change but button
I´m trying to change a spring jsp example to use freemarker. I changed all
im trying to change font globally for whole application, the problem is, i am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.