/* This is my horizontal field manager that will contain a centered field.
* AbstractHorizontalFieldManager is a Metova specific manager that handles
* initialization and loading automatically.
*/
private class MyHorizontalFieldManager extends AbstractHorizontalFieldManager {
private Field field;
public MyHorizontalFieldManager() {
/* if we do not use all width, then the horizontal field manager
* will shrink to the size of it's contents
*/
super( USE_ALL_WIDTH | NO_HORIZONTAL_SCROLL );
}
protected void initializeFields() {
setField( new AbstractButton( "My Button", new Action() {
public void run() {
log.debug( "My button was pressed." );
}
} ) );
}
protected void addFields() {
add( getField() );
}
protected void sublayout( int width, int height ) {
super.sublayout( width, height );
width = getWidth();
height = getHeight();
Field field = getField();
if ( field != null && equals( field.getManager() ) ) {
int x = (int) ( ( width - field.getWidth() ) * 0.50 );
setPositionChild( field, x, 0 );
}
}
private Field getField() {
return field;
}
private void setField( Field field ) {
this.field = field;
}
}
Comments (2)
Jul 28, 2009
Mark McEver says:
I think the official BB way to do this is to give the field the Field.FIELD_HCEN...I think the official BB way to do this is to give the field the Field.FIELD_HCENTER style, add the field to a VFM, then add that VFM to the HFM (see Field Alignment Using RIM's Alignment Styles). Why aren't we doing it this way?
Jul 20, 2009
Martin Reed says:
With the alignment styles you have three choices: left, center, right. If you wa...With the alignment styles you have three choices: left, center, right. If you want more then you end up nesting Managers which will cause performance issues. With this method you have total control of the position.