my custom verticalfieldmanger
public class Custom_TopField extends VerticalFieldManager {
private static final int FIELD_HEIGHT = 70;
private LabelField maintitle;
private String _text;
Custom_TopField(int color, String text) {
super(Manager.NO_VERTICAL_SCROLL);
_text = text;
Background background = BackgroundFactory.createSolidBackground(color);
setBackground(background);
maintitle = new LabelField(_text, Field.FIELD_VCENTER | Field.FIELD_HCENTER);
Font font = Font.getDefault().derive(Font.BOLD, 35);
maintitle.setFont(font);
add(maintitle);
}
protected void sublayout(int width, int height) {
width = Math.min(width, getPreferredWidth());
height = Math.min(height, getPreferredHeight());
setExtent(width, height);
}
public int getPreferredHeight() {
return FIELD_HEIGHT;
}
public int getPreferredWidth() {
return Display.getWidth();
}
public void paint(Graphics graphics) {
int rectHeight = getPreferredHeight();
int rectWidth = getPreferredWidth();
graphics.drawRect(0, 0, rectWidth, rectHeight);
super.paint(graphics);
}
}
Although i add(maintitle) but it did not come out middle of the verticalfield.
You can try this:
Add flags to constructor:
Also to field:
This should center horizontally the field. You can try adding also the flags to center vertically, but very likely it won’t work, because VFM’s have issues with vertical scrolling. The rule is: to center horizontally, use a
VerticalFieldManager, to center vertically, use aHorizontalFieldManager. This is how you can center in vertical:You could theoretically work out a solution combining both approaches, and nesting one manager inside the other one.