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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:02:35+00:00 2026-06-02T01:02:35+00:00

I want to add two labelfields in a HorizontalFieldManager, I want to show two

  • 0

I want to add two labelfields in a HorizontalFieldManager, I want to show two labels as one left aligned and another right aligned like this

enter image description here

hfm1 = new HorizontalFieldManager(Manager.USE_ALL_WIDTH);
        hfm1.setMargin(10,0,10,0);
        l1 = new LabelField("Weight:");
        l2 = new LabelField("20");
        l1.setMargin(0,10,0,0);
        l2.setMargin(0,5,0,0);
        hfm1.add(l1);
        hfm1.add(l2);
  • 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-02T01:02:36+00:00Added an answer on June 2, 2026 at 1:02 am

    Try this code

    LabelField labl1=new LabelField("weight");
    LabelField labl2=new LabelField("20");
    JustifiedHorizontalFieldManager JustifiedHorizontalFieldManager=new JustifiedHorizontalFieldManager(labl1,labl2,true);
    add(JustifiedHorizontalFieldManager);
    

    JustifiedHorizontalFieldManager class is given below-

    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Manager;
    
    public class JustifiedHorizontalFieldManager extends Manager
    {
        private static final int SYSTEM_STYLE_SHIFT = 32;
    
        public Field _leftField;
        public Field _rightField;
    
        private boolean _giveLeftFieldPriority;
    
        public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority )
        {
            this( leftField, rightField, giveLeftFieldPriority, Field.USE_ALL_WIDTH );
        }
    
        public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority, long style )
        {
            super( style );
    
            _leftField = leftField;
            _rightField = rightField;
    
            add( _leftField );
            add( _rightField );
    
            _giveLeftFieldPriority = giveLeftFieldPriority;
        }
    
        public JustifiedHorizontalFieldManager( boolean giveLeftFieldPriority, long style )
        {
            super( style );
            _giveLeftFieldPriority = giveLeftFieldPriority;
        }
    
        public void addLeftField( Field field )
        {
            if( _leftField != null ) {
                throw new IllegalStateException();
            }
            _leftField = field;
            add( _leftField );
        }
    
        public void addRightField( Field field )
        {
            if( _rightField != null ) {
                throw new IllegalStateException();
            }
            _rightField = field;
            add( _rightField );
        }
    
        public int getPreferredWidth()
        {
            return _leftField.getPreferredWidth() + _rightField.getPreferredWidth();
        }
    
        public int getPreferredHeight()
        {
            return Math.max( _leftField.getPreferredHeight(), _rightField.getPreferredHeight() );
        }
    
        protected void sublayout( int width, int height )
        {
            Field firstField;
            Field secondField;
            if( _giveLeftFieldPriority ) {
                firstField = _leftField;
                secondField = _rightField;
            } else {
                firstField = _rightField;
                secondField = _leftField;
            }
    
            int maxHeight = 0;
    
            int availableWidth = width;
            availableWidth -= _leftField.getMarginLeft();
            availableWidth -= Math.max( _leftField.getMarginRight(), _rightField.getMarginLeft() );
            availableWidth -= _rightField.getMarginRight();
    
            layoutChild( firstField, availableWidth, height - firstField.getMarginTop() - firstField.getMarginBottom() );
            maxHeight = Math.max( maxHeight, firstField.getMarginTop() + firstField.getHeight() + firstField.getMarginBottom() );
            availableWidth -= firstField.getWidth();
    
            layoutChild( secondField, availableWidth, height - secondField.getMarginTop() - secondField.getMarginBottom() );
            maxHeight = Math.max( maxHeight, secondField.getMarginTop() + secondField.getHeight() + secondField.getMarginBottom() );
            availableWidth -= secondField.getWidth();
    
            if( !isStyle( Field.USE_ALL_HEIGHT ) ) {
                height = maxHeight;
            }
            if( !isStyle( Field.USE_ALL_WIDTH ) ) {
                width -= availableWidth;
            }
    
            setPositionChild( _leftField, _leftField.getMarginLeft(), getFieldY( _leftField, height ) );
            setPositionChild( _rightField, width - _rightField.getWidth() - _rightField.getMarginRight(), getFieldY( _rightField, height ) );
    
            setExtent( width, height );
        }
    
        private int getFieldY( Field field, int height )
        {
            switch( (int)( ( field.getStyle() & FIELD_VALIGN_MASK ) >> SYSTEM_STYLE_SHIFT ) ) {
                case (int)( FIELD_BOTTOM >> SYSTEM_STYLE_SHIFT ):
                    return height - field.getHeight() - field.getMarginBottom();
                case (int)( FIELD_VCENTER >> SYSTEM_STYLE_SHIFT ):
                    return field.getMarginTop() + ( height - field.getMarginTop() - field.getHeight() - field.getMarginBottom() ) / 2;
                default:
                    return field.getMarginTop();
            }
        }
    
    
        public Field getLeftField()
        {
            return _leftField;
        }
    
        public Field getRightField()
        {
            return _rightField;
        }
    
        public void replace( Field oldField, Field newField )
        {
            if( oldField == newField ) {
                // Nothing to do
                return;
            }
    
            if( oldField == _leftField ) {
                _leftField = newField;
            } else if( oldField == _rightField ) {
                _rightField = newField;
            }
            add( newField );
            delete( oldField );
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add two views one after the other, I used this way
I want to add two HTML elements to a Dom element one after another.
I want to add sometimes one, sometimes two different TextBlocks into a single grid
I've this piece of HTML: div.content div.one content div.two content div.three content I want
I want add two textview with orientation vertical(One below other) in a table row
I want to add two files together, which one of them has only 1
I want to add one HTML file into another. For example: I have header.html
I'm very new to C. I want to add two one dimensional integer array
I want to add two numbers together but when one of those numbers is
I want to add two parameters to LayoutParams: View bar1 = new View(this); bar1.setBackgroundResource(R.drawable.blue_bar);

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.