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
Developer
Posts: 166
Registered: ‎01-14-2009
My Device: Curve 8330
Accepted Solution

Align question

Hello,

I want to right align a HorizontalFieldManager into a HotizontalFieldManager that use all width.

So I have something like that :

 

 

HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.USE_ALL_WIDTH);HorizontalFieldManager rightManager= new HorizontalFieldManager(Manager.FIELD_RIGHT);hfm.add(right);

 

The problem is that rightManager is always at left.

If I add rightManager directly to the screen, it is align to the right. 

 

 

Thank you, have a nice day.

--
Samuel D.
Developer
Posts: 238
Registered: ‎08-26-2008
My Device: Not Specified

Re: Align question

Hi,

 

why do you want that??

What kind of problem do you want to solve using two horizontalFieldManagers like that?

 

Regards,

Jochen

Developer
Posts: 166
Registered: ‎01-14-2009
My Device: Curve 8330

Re: Align question

I need to align some contols like button to the left and some text to the right.

The problem is that I have a background that is composed by two image and

that background must resize according to the text.

 

 

I need some thing like that :

 

 

Thank you, have a nice day.

--
Samuel D.
Developer
Posts: 168
Registered: ‎11-01-2008
My Device: Galaxy S II
My Carrier: Meteor (Ireland)

Re: Align question

[ Edited ]

I got so frustrated that I wrote my own manager in the end. Source below. Use it as you see fit with absolutely no warranty whatsoever, etc., etc. If you find a significant bug or make any useful improvement please let me know.

 

 


package com.blah;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;

class HorizontalPairManager extends Manager
{
private final boolean m_favourLeft;

HorizontalPairManager(Field leftField, Field rightField)
{
this(leftField, rightField, false);
}

HorizontalPairManager(Field leftField, Field rightField, boolean favourLeft)
{
super(Manager.USE_ALL_WIDTH);
add(leftField);
add(rightField);
m_favourLeft = favourLeft;
}

protected void sublayout(int width, int height)
{
Field leftField = getField(0);
Field rightField = getField(1);

if (m_favourLeft)
{
layoutChild(leftField, width, height);
layoutChild(rightField, width - leftField.getWidth(), height);
}
else
{
layoutChild(rightField, width, height);
layoutChild(leftField, width - rightField.getWidth(), height);
}

int leftFieldHeight = leftField.getHeight();
int rightFieldHeight = rightField.getHeight();
if (leftFieldHeight > rightFieldHeight)
{
setPositionChild(leftField, 0, 0);
setPositionChild(rightField, width - rightField.getWidth(), (leftFieldHeight - rightFieldHeight) / 2);
setExtent(width, leftFieldHeight);
}
else
{
setPositionChild(leftField, 0, (rightFieldHeight - leftFieldHeight) / 2);
setPositionChild(rightField, width - rightField.getWidth(), 0);
setExtent(width, rightFieldHeight);
}
}
}

 

 

 

Message Edited by davidmccormack on 27/04/09 02:23 PM
Message Edited by davidmccormack on 27/04/09 02:24 PM
Highlighted
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Align question

Hi,

 

You  can use spacefield between your 2 components and add all your three components into one horizontal manager and this horizontalmanager into one verticalfield manager.

 

For eg,

 

Say you have one ButtonField and One LabelField

 

1) Create HorizontalManager rowManager.

2) Add first ButtonField into this rowManager and then add spacerField into this manager and labelField also in same rowManager.

3) If you want you can add this rowManager  into verticalFieldManager to create TableField like structure.

 

code for spacerField is given below

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=28663&query.id=20...

 

 

Please let me know whether it helped you or not.

 

 

 

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 166
Registered: ‎01-14-2009
My Device: Curve 8330

Re: Align question

[ Edited ]

Hello,

thank you for your help.

I already tried the Spacer but I don''t want to calculate

the size of my two fields each time I change the

content of one.

 

The custom manager solution worked just fine. 

Message Edited by SamuelD on 04-27-2009 11:07 AM
Thank you, have a nice day.

--
Samuel D.
Developer
Posts: 55
Registered: ‎09-09-2008
My Device: Not Specified

Re: Align question

 


davidmccormack wrote:

I got so frustrated that I wrote my own manager in the end. Source below. Use it as you see fit with absolutely no warranty whatsoever, etc., etc. If you find a significant bug or make any useful improvement please let me know.

 

 


package com.blah;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;

class HorizontalPairManager extends Manager
{
private final boolean m_favourLeft;

HorizontalPairManager(Field leftField, Field rightField)
{
this(leftField, rightField, false);
}

HorizontalPairManager(Field leftField, Field rightField, boolean favourLeft)
{
super(Manager.USE_ALL_WIDTH);
add(leftField);
add(rightField);
m_favourLeft = favourLeft;
}

protected void sublayout(int width, int height)
{
Field leftField = getField(0);
Field rightField = getField(1);

if (m_favourLeft)
{
layoutChild(leftField, width, height);
layoutChild(rightField, width - leftField.getWidth(), height);
}
else
{
layoutChild(rightField, width, height);
layoutChild(leftField, width - rightField.getWidth(), height);
}

int leftFieldHeight = leftField.getHeight();
int rightFieldHeight = rightField.getHeight();
if (leftFieldHeight > rightFieldHeight)
{
setPositionChild(leftField, 0, 0);
setPositionChild(rightField, width - rightField.getWidth(), (leftFieldHeight - rightFieldHeight) / 2);
setExtent(width, leftFieldHeight);
}
else
{
setPositionChild(leftField, 0, (rightFieldHeight - leftFieldHeight) / 2);
setPositionChild(rightField, width - rightField.getWidth(), 0);
setExtent(width, rightFieldHeight);
}
}
}

 

You will have problem if leftField width is too big and no enough space for rightField.