Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
ahmednaserfinal
Posts: 43
Registered: ‎07-22-2012
My Device: curve
My Carrier: syudent

Re: Align 3 Fields one at left,one at center and one at right

http://postimage.org/image/pnn8lxqv1/

i want to make footer of this field at the end of the layout

Please use plain text.
Contributor
Pougnet
Posts: 11
Registered: ‎10-14-2012
My Device: Developer
My Carrier: Developer

Re: Align 3 Fields one at left,one at center and one at right

This should do the trick:

super(NO_VERTICAL_SCROLL);    
setTitle("MyTitle");
        
// Left aligned vfm to hold the button
VerticalFieldManager left = new VerticalFieldManager(Manager.FIELD_LEFT);
ButtonField leftbutton = new ButtonField("left");
left.add(leftbutton);
        
// Centre aligned vfm to hold the label
VerticalFieldManager centre = new VerticalFieldManager(Manager.FIELD_HCENTER);
LabelField centrelabel = new LabelField("Centre");
centre.add(centrelabel);
        
// Right aligned vfm to hold the button
VerticalFieldManager right = new VerticalFieldManager(Manager.FIELD_RIGHT); 
ButtonField rightbutton = new ButtonField("right");
right.add(rightbutton); 
        
// Footer button
VerticalFieldManager bottom = new VerticalFieldManager(Manager.FIELD_BOTTOM);
ButtonField bottombutton = new ButtonField("bottom");
bottom.add(bottombutton);
        
// Create a 3x1 evenly spaced grid to hold the above vfms
GridFieldManager gridFieldManager = new GridFieldManager(2,3, Manager.USE_ALL_WIDTH); 
gridFieldManager.setColumnProperty(0, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setColumnProperty(1, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setColumnProperty(2, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setRowProperty(0, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setRowProperty(1, GridFieldManager.AUTO_SIZE, 0);

// Add the left vfm to the grid
VerticalFieldManager vfmLeft = new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT );
vfmLeft.add(left);
gridFieldManager.add(vfmLeft);  

// Add the centre vfm to the grid
VerticalFieldManager vfmCentre = new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT );
vfmCentre.add(centre);
gridFieldManager.add(vfmCentre);
        
// Add the right vfm to the grid
VerticalFieldManager vfmRight = new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT );
vfmRight.add(right);
gridFieldManager.add(vfmRight);
        
// Footer hfm
HorizontalFieldManager vfmLeftBottom = new HorizontalFieldManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT);
vfmLeftBottom.add(bottom);
gridFieldManager.add(vfmLeftBottom);

add(gridFieldManager);
        

 

Please use plain text.
Contributor
ahmednaserfinal
Posts: 43
Registered: ‎07-22-2012
My Device: curve
My Carrier: syudent

Re: Align 3 Fields one at left,one at center and one at right

also not i want i found class and i update it and its work fine thanks you alot for replay for me ant try to help me thanks again and this is the class that i use

package com.Ace.GUI;

import net.rim.device.api.system.Display;
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 _leftField1;
	public Field _centerField;
	public Field _rightField;

	private boolean _giveLeftFieldPriority;

	public JustifiedHorizontalFieldManager(Field leftField, Field leftField1,
			Field centerField, Field rightField, boolean giveLeftFieldPriority) {
		this(leftField, leftField1, centerField, rightField,
				giveLeftFieldPriority, Field.USE_ALL_WIDTH);
	}

	public JustifiedHorizontalFieldManager(Field leftField, Field leftField1,
			Field centerField, Field rightField, boolean giveLeftFieldPriority,
			long style) {
		super(style);

		_leftField = leftField;
		_leftField1 = leftField1;
		_centerField = centerField;
		_rightField = rightField;

		add(_leftField);
		add(_leftField1);
		add(_centerField);
		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 addLeftField1(Field field) {
		if (_leftField1 != null) {
			throw new IllegalStateException();
		}
		_leftField1 = field;
		add(_leftField1);
	}

	public void addCenterField(Field field) {
		if (_centerField != null) {
			throw new IllegalStateException();
		}
		_centerField = field;
		add(_centerField);
	}

	public void addRightField(Field field) {
		if (_rightField != null) {
			throw new IllegalStateException();
		}
		_rightField = field;
		add(_rightField);
	}

	public int getPreferredWidth() {
		return Display.getWidth();
	}

	public int getPreferredHeight() {
		return Math.max(_leftField.getPreferredHeight(),
				_rightField.getPreferredHeight());
	}

	protected void sublayout(int width, int height) {
		Field firstField;
		Field secondField;
		Field thirdField;
		Field fourthField;
		firstField = _leftField;
		secondField = _leftField1;
		thirdField = _centerField;
		fourthField = _rightField;

		int maxHeight = 0;

		int availableWidth = width;
		availableWidth -= _leftField.getMarginLeft();
		availableWidth -= _leftField1.getMarginLeft();
		availableWidth -= _centerField.getMarginRight();
		availableWidth -= Math.max(
				Math.max(_leftField.getMarginRight(),
						_rightField.getMarginLeft()),
				Math.max(_leftField1.getMarginLeft(),
						_centerField.getMarginRight()));
		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();

		layoutChild(
				thirdField,
				availableWidth,
				height - thirdField.getMarginTop()
						- thirdField.getMarginBottom());
		maxHeight = Math.max(
				maxHeight,
				thirdField.getMarginTop() + thirdField.getHeight()
						+ thirdField.getMarginBottom());
		availableWidth -= thirdField.getWidth();

		layoutChild(
				fourthField,
				availableWidth,
				height - fourthField.getMarginTop()
						- fourthField.getMarginBottom());
		maxHeight = Math.max(maxHeight, fourthField.getMarginTop()
				+ fourthField.getHeight() + fourthField.getMarginBottom());
		availableWidth -= fourthField.getWidth();

		if (!isStyle(Field.USE_ALL_HEIGHT)) {
			height = maxHeight;
		}
		if (!isStyle(Field.USE_ALL_WIDTH)) {
			width -= availableWidth;
		}

		setPositionChild(_leftField, 15,
				getFieldY(_leftField, height));
		setPositionChild(_leftField1, _leftField.getWidth()+15,
				getFieldY(_leftField1, height));
		setPositionChild(_centerField, (width - _centerField.getWidth()) / 2,
				getFieldY(_centerField, 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 getLeftField1() {
		return _leftField1;
	}

	public Field getCenterField() {
		return _centerField;
	}

	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 == _leftField1) {
			_leftField1 = newField;
		} else if (oldField == _centerField) {
			_centerField = newField;
		} else if (oldField == _rightField) {
			_rightField = newField;
		}
		add(newField);
		delete(oldField);
	}

}

 thank you again

Please use plain text.
Contributor
Pougnet
Posts: 11
Registered: ‎10-14-2012
My Device: Developer
My Carrier: Developer

Re: Align 3 Fields one at left,one at center and one at right

Not a problem.

Also, if you didn't know, there are many more classes like that in the Advanced UI package. Here's a link:
http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-manage...
Please use plain text.