views:

448

answers:

2

I am using Eclipse & JDE 4.5.0 plug-in. How to align fields vertically. Can we align fields like LEFT_BOTTOM,RIGHT_BOTTOM, LEFT_VCENTER, RIGHT_VCENTER, CENTER(vertically & horizontally), BOTTOM_CENTER, etc...? Please help me..

Thank You...

+2  A: 

BlackBerry UI field managers are notoriously annoying when dealing with field alignment. Managers seem to ignore all style flags (like HCENTER, VCENTER, etc) so the only way you'll be able to do this is to override the sublayout method of your manager and do it yourself.

Here's a little snippet to show you what I mean. This particular code actually does horizontal centering, not vertical centering, but once you get the idea you can implement any styles you need.

VerticalFieldManager mainmanager  = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT)
{
 protected void sublayout( int width, int height ) {

     super.sublayout( width, height );

     width = getWidth();
     height = getHeight();

     for (int i = 0;i < this.getFieldCount() - 1; i++)
     {
      Field field = this.getField(i);
      //this positions the item in the middle of the manager
      int x = (int)((width - field.getWidth()) * 0.50);
      setPositionChild(field, x, field.getTop());
     }
 }

Please note that the USE_ALL_WIDTH and USE_ALL_HEIGHT style flags are important. If you want to do things like vertical centering, bottom-right aligning, etc. you will need to write the positioning code yourself. For bottom-right alignment for example you could set the x position to the width of the manager minus the width of the field, and the y position to the height of the manager minus the height of the field.

If you want to be able to use one custom manager class to handle multiple different styles (like bottom right, bottom left) you can add some logic in sublayout to check the field's style flag and then position the field appropriately.

Hopefully this all makes sense and helps you. :)

Anidamo
A: 

HorizontalFieldManager only accepts Vertical Alignment Styles and VerticalFieldManager only accept Horizontal Alignment. That's it. Annoying ++