Blackberry WARNING: Cannot layout field, insufficient height or width - blackberry

I'm getting the following error when a screen should appear:
"WARNING: Cannot layout field, insufficient height or width".
Working with BB 5.0.
This screen es called from 3 different screen, and its shows 50% of the screen or 80%, depending on which screen is pushing it.
This one only have one banner at the top (field), some BasicEditField, one DateField, a vew ObjectChoiceField and at the end 2 buttons.
Why is this error showing up now? (2 days ago it didnt and is the same screen that worked fine before). Where should i check for errors?
Also, is there some limit of height or width that a screen can manage?
Code for the banner,
public static Field getBanner() {
Background bg = BackgroundFactory.createSolidBackground(Color.WHITE);
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.USE_ALL_WIDTH | Field.FIELD_VCENTER);
final Bitmap logo = Bitmap.getBitmapResource("logo_40px.png");
BitmapField _bitmap1 = new BitmapField(logo);
int i = Display.getWidth();
i = i - logo.getWidth();
i = i / 2;
_bitmap1.setSpace(i, 5);
hfm.add(_bitmap1);
hfm.setBackground(bg);
return hfm;
}
Regards.
update:
on the screen creation i have this:
super(MainScreen.VERTICAL_SCROLL_MASK | MainScreen.VERTICAL_SCROLLBAR)
Without this, its works fine the screen. But i wont be able to scroll down, right?

You are adding both _bitmap1 and vfm to hfm, and vfm has Field.USE_ALL_WIDTH set. It would work better, I think, to add _bitmap1 to vfm.
EDIT
It may be that your logo (with the added space) is too big for the banner area on the screen. Perhaps something like this would work:
public static Field getBanner() {
Background bg = BackgroundFactory.createSolidBackground(Color.WHITE);
final Bitmap logo = Bitmap.getBitmapResource("logo_40px.png");
final BitmapField _bitmap1 = new BitmapField(logo);
_bitmap1.setSpace((Display.getWidth() - logo.getWidth()) / 2, 5);
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.USE_ALL_WIDTH | Field.FIELD_VCENTER) {
protected void sublayout(int width, int height) {
super.sublayout(width, height);
setExtent(width, Math.min(_bitmap1.getPreferredHeight(), height));
}
}
hfm.add(_bitmap1);
hfm.setBackground(bg);
return hfm;
}

Related

Set the text in the center of the screen in Button Field in Blackberry?

I am an an Android Developer, developing an Blackberry application.
I have created a button of full width of screen. Getting problem in shifting the text to the center of the button area.
Used below code :
ButtonField _contactButton = new ButtonField(Constants.contactButtonTitle,Field.FIELD_HCENTER|Field.USE_ALL_WIDTH |
Field.ACTION_INVOKE | Field.FOCUSABLE | ButtonField.CONSUME_CLICK){
protected void layout(int width, int height) {
super.layout(width, height);
HARD_CODED_HEIGHT = this.getHeight()/2 + 6;
this.setExtent(contactButtonWidth, HARD_CODED_HEIGHT);
}
public int getPreferredWidth() {
return contactButtonWidth;
}
};
Now using the below code :
ButtonField _contactButton = new ButtonField(Constants.contactButtonTitle,Field.FIELD_VCENTER|Field.USE_ALL_WIDTH |
Field.ACTION_INVOKE | Field.FOCUSABLE | ButtonField.CONSUME_CLICK){
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
}
public int getPreferredWidth() {
return (Display.getWidth()-60);
}
};
Still getting the issue .. text of my button align to right corner. Please suggest
ButtonField appears to be a little 'broken'. But it also appears to be consistently broken in all the OS Levels that I have tested (OS 5.0 to OS 7.1), so I think we can achieve what you want by working round the broken bits and be confident the workaround will work in all levels you want.
As has been noted, ButtonField ignores USE_ALL_WIDTH, but does respect preferredWidth. So if you want to set the width of your ButtonField, then just override getPreferredWidth(). You should not do anything with width in layout.
Now you are using the styles for ButtonField already. Given that we have discarded USE_ALL_WIDTH as a useful style, I note that you also use FIELD_HCENTER. You should be aware that this is actually a directive to the Manager that is positioning this Field - telling the Manager to position the Field in the centre of the width the Manager has available. This style does not relate to how the contents of the ButtonField are drawn.
For that, you can look to use DrawStyle. By default, ButtonField uses DrawStyle.RIGHT. And it respects DrawStyle.Left - the text will be drawn on the left. It does not however, respect DrawStyle.HCENTER. So to get centred text, we need to paint the text ourselves.
There is one more complication. ButtonField passes a Context area into its paint() method, not the full Field canvas - presumably it does not pass in the edges because these are painted by a border. So to centre the text appropriately, we have to use the clipping region that has been passed in.
Here is the final, hopefully working, ButtonField. I appreciate you will have to spend some time creating a class for this, I'm sorry, I've been lazy and done in it 'in-line'. Please publish your CenteredTextButtonField class if you create one....
final String buttonText = "Test";
ButtonField _contactButton = new ButtonField(" ",
Field.ACTION_INVOKE | Field.FOCUSABLE | ButtonField.CONSUME_CLICK){
public int getPreferredWidth() {
return contactButtonWidth;
}
protected void paint(Graphics graphics) {
super.paint(graphics);
XYRect clippingRect = graphics.getClippingRect();
int centreY = (clippingRect.height - graphics.getFont().getHeight()) / 2;
graphics.drawText(buttonText, 0, centreY, DrawStyle.HCENTER, clippingRect.width);
}
};
USE_ALL_WIDTH is our instruction to the field. Surprisingly, ButtonField ignores such instructions. Even more surprisingly, it honors its own getPreferredWidth (as illogical as it sounds).
So drop that USE_ALL_WIDTH and define your ButtonField like this:
ButtonField testBtn = new ButtonField("Button") {
public int getPreferredWidth() {
return Display.getWidth();
}
};

radio button not visible in a HorizontalFieldManager in blackberry?

I am working on a blackberry application which includes radio button controls.
HorizontalFieldManager hr = new HorizontalFieldManager();
setTitle("UI Component Sample");
RadioButtonGroup rbg = new RadioButtonGroup();
RadioButtonField r1 = new RadioButtonField("Option 1",rbg,true);
RadioButtonField r2 = new RadioButtonField("Option 2",rbg,false);
hr.add(r1);
hr.add(r2);
add(hr);
Working with this code I can see my both radio buttons in curve device but when I install my app in Torch device, only 1st radio button is visible on the screen.
Getting problem in showing one radio group in a horizontal field.
It works when i use a vertical field for a group.
And Horizontal and vertical both works when i works on curve device.
Please suggest what type of bus or problem this is.
In OS 6, RadioButtonField causes some problem regarding its width. Overriding the layout(int, int) method may solve your problem. Try following code.
RadioButtonGroup rbg = new RadioButtonGroup();
RadioButtonField rbf = new RadioButtonField("Label", rbg, true) {
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
}
};

Disable vertical scrolling in BlackBerry

In BlackBerry I have developed a screen which display a image of size
480 X 360 in background. My BB screen is of size 480 X 360. As the image is bit big in size when I scroll vertically the screen gets scrolled and disturbs my screen.
I want to lock the scrolling such that I will not be able to do vertical scrolling.
My code is as follows:
public LaunchXtcMsngrScreen()
{
int intwidth = Display.getWidth();
int intheight = Display.getHeight();
//getting the height/width of BB screen
Debugger.debug(UrlInfo.workflow_File,"Screen Height ="+intheight);
Debugger.debug(UrlInfo.workflow_File,"Screen Width ="+intwidth);
BMbackground = Bitmap.getBitmapResource("xtclogo.jpg");
VerticalFieldManager VFM = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH
| VerticalFieldManager.USE_ALL_HEIGHT
| VerticalFieldManager.NO_VERTICAL_SCROLL
| VerticalFieldManager.NO_VERTICAL_SCROLLBAR)
{
//Override the paint method to draw the background image.
public void paint(Graphics graphics)
{
//Draw the XTC Messenger logo
graphics.drawBitmap(0, 0,Display.getWidth(),Display.getHeight(),BMbackground, 0, 0);
super.paint(graphics);
}
};
Bitmap registerbitmap = Bitmap.getBitmapResource("register_button.PNG");
BFregister = new ImageButtonField(registerbitmap);
BFregister.setMargin(245,0,0,190);//vertical pos,0,0,horizontal pos
VFM.add(BFregister);
add(VFM);
}
add the below code as the next line of the function declaration
super(NO_VERTICAL_SCROLL|NO_VERTICAL_SCROLLBAR);
If you have placed your image inside a manager then u can follow any idea viz:
1) either create a custom manager and write setExtent(480,360) in its sublayout method.
2) you can also write setExtent(480,360) in any HorizontalfieldManager or VerticalFieldManager's sublayout method
have you tried using USE_ALL_WIDTH and USE_ALL_HEIGHT in any manager?

Can't align fields horizontally on custom pop up screen in Blackberry

What I want to achieve is to have a custom popup screen with specified width and height.
On that screen I add two buttons which stay in one row and align center horizontally.
public class CustomPopupScreen extends PopupScreen {
ButtonField minimizeBf;
ButtonField cancelBf;
HorizontalFieldManager hfm;
public CustomPopupScreen() {
super(new VerticalFieldManager());
minimizeBf = new ButtonField("Minimize", FIELD_HCENTER|Field.USE_ALL_WIDTH);
cancelBf = new ButtonField("Cancel", FIELD_HCENTER|Field.USE_ALL_WIDTH);
hfm = new HorizontalFieldManager(FIELD_HCENTER|Field.USE_ALL_WIDTH);
hfm.add(minimizeBf);
hfm.add(cancelBf);
add(hfm);
//add(minimizeBf);
//add(cancelBf);
}
protected void sublayout(int width, int height) {
// TODO Auto-generated method stub
int xPos = 0;
int yPos = 0;
int sideMargin = 30;
int screenWidth = width - (2 * sideMargin);
int screenHeight = 100;
layoutDelegate(screenWidth, screenHeight);
//setPositionDelegate(0, 0);
super.sublayout(screenWidth, screenHeight);
setExtent(screenWidth, screenHeight);
xPos = (width - screenWidth) / 2;
yPos = (height - screenHeight) / 2;
setPosition(xPos, yPos);
// layout(screenWidth, screenHeight);
}
}
If I add those buttons to the screen, then it will align center horizontally, but the buttons appear on different row, while I want it to appear in the same row.
Can somebody tell me where have I code wrong ?
Try removing the USE_ALL_WIDTH flag from your HorizontalFieldManager allocation. That should do the trick.
Try putting a couple of vertical field managers, each taking half the available width, inside the horizontal manager. then add one button to each of the vertical managers.
I was just wondering the purpose of having a custom size. There is often a correct way to do something without having to modify the layout manually. If you share your end goal, we may be able to help better. Since it almost appears that you want to simply make two buttons be side to side. To add width and height you can add spacers (add(new SeparatorField())) to the field managers and specify their width/height as well as where in the manager you want them. This would allow all the fields to use their default layout patterns.
just do one
hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
i think it might help you just give it a try.

Placement of ButtonField

i want to place the Buttons as displayed in the image:
alt text http://www.freeimagehosting.net/uploads/413b8990b3.png
for this i am using the following code but it is not working for me can any one please help me out
topbarManager = new HorizontalFieldManager();
topbarLeftManager = new HorizontalFieldManager(Field.FIELD_LEFT);
topbarRightManager = new HorizontalFieldManager(Field.FIELD_RIGHT);
topbarCenterManager = new HorizontalFieldManager(Field.FIELD_HCENTER);
topbarLeftManager.add(new ButtonField("first"));
topbarRightManager.add(new ButtonField("second"));
topbarCenterManager.add(new ButtonField("third"));
topbarManager.add(topbarLeftManager);
topbarManager.add(topbarCenterManager);
topbarManager.add(topbarRightManager);
i am not getting the result as i required.
can any one please Help me out.
Thanks a lot
according to docs.
HorizontalFieldManager layout manager arranges UI components in a single horizontal row starting at the left side of the screen and ending at the right side of the screen. Because this layout manager arranges UI components horizontally, you cannot apply horizontal style bits to UI components (for example, Field.FIELD_LEFT, Field.FIELD_HCENTER, or Field.FIELD_RIGHT). You can apply vertical style bits (for example, Field.FIELD_TOP, Field.FIELD_BOTTOM, or Field.FIELD_VCENTER).
so if you want to see Field.FIELD_LEFT effect use
VerticalFieldManager hfm = new VerticalFieldManager(Manager.USE_ALL_WIDTH);
instead of HorizontalFieldManager, you will see the stair case like effect.
To layout UI best thing is use custom layout
HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.USE_ALL_WIDTH){
protected void sublayout(int maxWidth, int maxHeight) {
Field f;
int w = Display.getWidth();
int x=0;
for (int i = 0; i < getFieldCount(); i++) {
f = getField(i);
layoutChild(f, f.getPreferredWidth(), f.getPreferredHeight());
setPositionChild(f, x, 0);
x+=(w-f.getWidth())/2;
}
setExtent(maxWidth, maxHeight);
}
};

Resources