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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:33:16+00:00 2026-05-11T23:33:16+00:00

I want to align a Custom Button Field (the Star on the Screenshot) to

  • 0

I want to align a Custom Button Field (the Star on the Screenshot) to the center in a Horizontal Manager

alt text

Definition of the HFM

final HorizontalFieldManager _navigation = new HorizontalFieldManager(HorizontalFieldManager.NO_VERTICAL_SCROLL | HorizontalFieldManager.FIELD_VCENTER | Field.USE_ALL_WIDTH)
{    
 protected void paint(Graphics graphics)
 {
     graphics.setGlobalAlpha(100);

     int[] xInds = new int[]{0, getExtent().width, getExtent().width, 0};
     int[] yInds = new int[]{0, 0, getExtent().height, getExtent().height};
     final int[] cols = new int[]{Color.WHITE, Color.WHITE, color_computacenter_light_blue, color_computacenter_light_blue};

     graphics.drawShadedFilledPath(xInds, yInds, null, cols, null);
     super.paint(graphics);
 }
 protected void sublayout(int maxWidth, int maxHeight)
    {
        super.sublayout(maxWidth, maxHeight);
        setExtent(maxWidth, navigation_vertical_manager_height);
    }
};

Custom Field (partial)

public class NavigationButton extends Field
{
    private String label;
    Bitmap img;
    int horizontalPadding = 4;
    int verticalPadding = 10;
    static int height;
    static int weight;
    ToolTip _tooltip;

    public NavigationButton(String name, Bitmap img) 
    {
        label = name;
        this.img = img;
        this.height = img.getHeight() + 4;
        this.weight = img.getWidth()  + 2;
    }

    public NavigationButton(String name, Bitmap img, long style) 
    {
        super(style);
        label = name;
        this.img = img;
        this.height = img.getHeight() + 4;
        this.weight = img.getWidth()  + 2;
    }

    protected void layout(int maxWidth, int maxHeight) 
    {  
        setExtent(maxWidth, maxHeight);
        // setExtent(Math.min(weight, maxWidth), Math.min(height, maxHeight));
    }

    protected void paint(Graphics graphics) 
    {
        // Draw background  
        graphics.setGlobalAlpha(255);
        if(isFocus())
        {   
            graphics.setColor(0x005AA1);
            graphics.drawRoundRect(0 ,0 , weight + 1, height + 1, 2, 2);
        }
        if (img != null) 
        {
            graphics.drawBitmap(0, 0 , img.getWidth(), img.getHeight(), img, 0, 0);
        }
    }

[…]

Any Ideas, what I’m doing wrong?!

Thanks!

  • 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-11T23:33:16+00:00Added an answer on May 11, 2026 at 11:33 pm

    I haven’t tested this code out, but I suspect your problem is in the layout method of your field:

    protected void layout(int maxWidth, int maxHeight) 
        {  
            setExtent(maxWidth, maxHeight);
            // setExtent(Math.min(weight, maxWidth), Math.min(height, maxHeight));
        }
    

    Is there a reason you commented that line? I think what’s happening is that your custom field is taking up the whole width, and in your paint method you’re drawing the bitmap at the extreme left, making it look like the field is aligned left. If you uncomment that line, and add a field style bit of Field.FIELD_HCENTER when you construct your field it should work.

    Alternatively, you can keep the layout as is, and just draw the bitmap centered, by changing the line in your paint method to something like this

    graphics.drawBitmap((this.getWidth()-img.getWidth())/2, 0 , img.getWidth(), img.getHeight(), img, 0, 0);
    

    The field will still take up the whole width, but the image will be centered. This might cause unexpected behavior on touchscreen devices (i.e. the Storm).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want align the div to center. like this I have tried margin-top, vertical-align
Possible Duplicate: How to center form in twitter bootstrap? I want to align my
I want to align the contents or items of ExpanderView in horizontal layout instead
I want to align the buttons as shown bellow, for this, I used relative
I want to align my logo at the top but failed to do so
i want to align two textboxes with their display names ,side by side in
I want to align two buttons with a linear layout, one on the left,
I want to align some text to the top of a div. It seems
I want to align a list of links to be centered within a div.
i am having 4 ButtonField and i want to align all the buttons horizontally.

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.