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 7048707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:55:27+00:00 2026-05-28T02:55:27+00:00

How would I go about creating a custom ButtonField that includes an icon? I

  • 0

How would I go about creating a custom ButtonField that includes an icon? I have found several different sources for a ButtonField with a custom background Bitmap, but I want to have a button with an Icon and text under it. I can not find anyt informaiton about this, maybe someone here could help me out?

Cheers

  • 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-28T02:55:28+00:00Added an answer on May 28, 2026 at 2:55 am

    Try this

    package com.MYAPP.controls;
    
    
    import com.MYAPP.bll.Log;
    
    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.Field;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.Graphics;  
    
    public class ButtonControl extends Field {
       private Bitmap selectedBitmap;
       private Bitmap unSelectedBitmap;
       private String _label; 
       protected boolean focus = false; 
       protected int bWidth = 0;
       protected int bHeight = 0;
       int padding = 0; 
       Font font=Font.getDefault();
       public ButtonControl(String icon, String label) {
           super(Field.FOCUSABLE); 
           _label = label; 
           try {
    
    
                     selectedBitmap = Bitmap.getBitmapResource(icon + "_focus.png");
                     unSelectedBitmap =Bitmap.getBitmapResource(icon + ".png");
                     padding = 0;
    
           } catch (Exception ex) {
                   Log.Error(ex, "Cannot load icon {" + icon + "}");
           }
    
           bWidth = selectedBitmap.getWidth();
           bHeight = selectedBitmap.getHeight();
       }
    
       protected void onFocus(int direction) {
           focus = true;
           invalidate();
       }
    
       protected void onUnfocus() {
           focus = false;
           invalidate();
       }
    
       public void drawFocus(Graphics g, boolean on) {
               // do nothing... this is handled in paint...
       }
    
       protected int moveFocus(int amount, int status, int time) {
           // This ensures background is redrawn properly if this control is
           // the first or last in a series (eliminate white background issue)
           invalidate();
           return super.moveFocus(amount, status, time);
       }
    
       protected void moveFocus(int x, int y, int status, int time) {
           // This ensures background is redrawn properly if this control is
           // the first or last in a series (eliminate white background issue)
           invalidate();
           super.moveFocus(x, y, status, time);
       }
    
       int _labelWidth;
       int posbitmapX=0;
       int x=0;
       int y = 0;
       protected void paint(Graphics g) { 
           int oldColor = g.getColor();
           Font oldFont = g.getFont();
           g.setFont(getTextFont());  
           x = (getWidth() - bWidth) / 2;  
           if (focus) {
                   g.setColor(Color.WHITE);
                   g.drawBitmap(x, y, bWidth, bHeight, selectedBitmap, 0, 0);
           } else {
                   g.setColor(Color.BLACK);
                   g.drawBitmap(x, y, bWidth, bHeight, unSelectedBitmap, 0, 0);
           } 
    
           g.setFont(getTextFont());
           _labelWidth = getTextFont().getAdvance(_label);
           g.drawText(_label, 0, bHeight + 2, Graphics.HCENTER, getWidth());
           g.setColor(oldColor);
           g.setFont(oldFont);
       }
    
    
       protected void layout(int width, int height) {
               setExtent(getPreferredWidth(), getPreferredHeight());
       } 
    
       private Font getTextFont() { 
           return font;
       }
    
       public int getPreferredWidth() { 
           return selectedBitmap.getWidth();
       }
    
       public int getPreferredHeight() {
               return (bHeight + 2 + font.getHeight() + 2);
       }
    
       protected boolean keyChar(char key, int status, int time) {
           if (key == Characters.ENTER) { 
               return this.navigationClick(status, time);
           }
    
           return super.keyChar(key, status, time);
      } 
       protected boolean navigationClick(int status, int time) { 
           fieldChangeNotify(1); 
               return true;
      }
       protected void fieldChangeNotify(int context) {
           try {
                   this.getChangeListener().fieldChanged(this, context);
           } catch (Exception e) {
                   Log.Debug("Error responding to field change: " + e);
           }
       } }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would one go about creating a custom action in Cocos2D that was able
How would I go about creating a custom UIView that is like the event
How would I go about creating a real world form creation class that I
How would I go about creating a Google map that allows the user to
I'm trying to find documentation on how one would go about creating a custom
How would I go about creating a custom number pad like what is used
How would one go about creating an ipad app that has a similar view
I have a question about creating and managing events inside an ascx custom web
I am just learning about app.config in respect of creating custom sections. I have
I'm curious... how would I go about creating a custom progress bar like the

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.