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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:57:01+00:00 2026-06-08T17:57:01+00:00

i am developing one app in which 9i have taken CustomeButtonField class for Make

  • 0

i am developing one app in which 9i have taken CustomeButtonField class for Make custom Button. in which i got custom button as expectation but Button of Text are Not Align Center.
can you please let me know that in CustomeButtonFiel that how can i make button text as Center.

Here is Code

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.*;

public class CustomButtonField extends Field
{
    Bitmap Unfocus_img, Focus_img, current_pic;
    int width;
    String text;
    Font font;   
    int custColor;
    CustomButtonField(int width, String text, Bitmap onFocus, Bitmap onUnfocus, long style,int custColor)
    {
        super(style);
        Unfocus_img = onUnfocus;
        Focus_img = onFocus;
        current_pic = onFocus;
        this.text = text;
        this.width = width;
        this.custColor = custColor;
    }
    protected void layout(int width, int height) 
    {
        setExtent(current_pic.getWidth(), current_pic.getHeight());        
    }
    protected void paint(Graphics graphics) 
    {
        try
        {
                FontFamily fntFamily = FontFamily.forName("BBAlpha Sans");
                font = fntFamily.getFont(Font.BOLD,20);              
        }
        catch(Exception e)
        {
            font = Font.getDefault();

        }
        graphics.setFont(font);


        graphics.setColor(custColor); 


        graphics.drawBitmap(0, 0, current_pic.getWidth(), current_pic.getHeight(), current_pic , 0 , 0);
        graphics.drawText(text, width, 7);
        graphics.setDrawingStyle(Graphics.HCENTER, true);
    }
    protected void onFocus(int direction) 
    {
        super.onFocus(direction);
        current_pic = Unfocus_img;
        this.invalidate();
    }
  protected void drawFocus(Graphics graphics, boolean on) 
  {

    }
    protected void onUnfocus() 
    {
        super.onUnfocus();
        current_pic = Focus_img;
        invalidate();
    }
    public boolean isFocusable() {
        return true;
    }
    protected boolean navigationClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }
} 
  • 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-06-08T17:57:03+00:00Added an answer on June 8, 2026 at 5:57 pm

    Replace last 3 lines of the paint method with following lines:

    int xText = (getWidth() - font.getAdvance(text)) / 2;
    int yText = (getHeight() - font.getHeight()) / 2;
    
    graphics.drawBitmap(0, 0, current_pic.getWidth(), current_pic.getHeight(), current_pic , 0 , 0);
    graphics.drawText(text, xText, yText);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing one small app in which i have multiple NSURLConnection.I have created
I am developing a app in which i have rotate a delete button when
I'm developing an app which contain TabHost ,in one of those tabs i have
I am developing one app which is based on the webservice and fetch the
I am developing one app , which is required to integrate Google checkout.I am
I'm developing a web app using a cakephp. I've one function in which I
I am developing native iPhone app. I have one requirement that, there are 5
I am developing a Facebook app. I have a server side OAuth flow which
I'm developing a QA web-app which will have some points to evaluated assigned to
Hello Everyone, I am developing an app which have to show all the restaurants

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.