BlackBerry GridLayoutManager column always display field in the center - blackberry

I just create a simple blackberry application which use GridLayoutManager for manage my field in the screen, below the snippet:
GridFieldManager gfm = new GridFieldManager(2, 3, 0);
gfm.add(new LabelField("AGUS ZULVANI"));
gfm.add(new LabelField("B"));
gfm.add(new LabelField("C"));
gfm.add(new LabelField("D"));
gfm.add(new LabelField("E"));
gfm.add(new LabelField("F"));
gfm.setColumnPadding(20);
gfm.setColumnProperty(0, GridFieldManager.FIXED_SIZE, 100);
add(gfm);
Label "D" display in center align..
how I can make it to left align?

I don't know off the top of my head if GridFieldManager respects the style bits, but the first thing I would try is: new LabelField("D", Field.FIELD_LEFT)

Related

Vaadin Alignment with GridLayout to center over cells

I trying to get image and title to be in the center
the login in box works OK
private void createTitle(final AbstractOrderedLayout parentLayout) {
GridLayout layout = new GridLayout(6, 2);
layout.setSpacing(true);
layout.setWidth( 100, Sizeable.Unit.PERCENTAGE );
layout.setHeight( 100, Sizeable.Unit.PERCENTAGE );
parentLayout.addComponent(layout);
parentLayout.setComponentAlignment(layout, Alignment.TOP_CENTER);
Embedded image = new Embedded("", new ClassResource("Icon_25x32.png"));
layout.addComponent(image, 2, 0);
layout.setComponentAlignment(image, Alignment.TOP_CENTER);
Label titleLabel = new Label("YT-100 ATU Control Center");
titleLabel.addStyleName("v-label-largeTitleText");
//layout.addComponent(titleLabel, 3, 1);
layout.addComponent(titleLabel, 3, 1, 4,1);
layout.setComponentAlignment(titleLabel, Alignment.TOP_CENTER);
mUserLayout = new GridLayout(2, 2);
mUserLayout.setSpacing(true);
layout.addComponent(mUserLayout, 5, 0);
layout.setComponentAlignment(mUserLayout, Alignment.MIDDLE_CENTER);
}
why does this not center?
Fixed:
titleLabel.setSizeUndefined();
and
.v-caption-centered, input.centered {
text-align: center;
}
notice that title label has 100% width by default, so it will take the entire width of the containing layout cell. Centering is only meaningful for components that take less width than the containing cell. Hence, you'd need to set the label width to undefined.

BlackBerry Field Alignment

I am using HorizontalFieldManager with Field.USE_ALL_WIDTH and Field.FIELD_HCENTER but Field.FIELD_HCENTER is not working below is how I am constructing HorizontalFieldManager
HorizontalFieldManager horizontalContainer = new HorizontalFieldManager(Field.USE_ALL_WIDTH | FIELD_HCENTER);
The
Field class provides the following style bits for alignment:
Horizontal alignment styles
FIELD_LEFT
FIELD_HCENTER
FIELD_RIGHT
Vertical alignment styles
FIELD_TOP
FIELD_VCENTER
FIELD_BOTTOM
The horizontal alignment styles are only recognized when a Field is added to a VerticalFieldManager, and the vertical alignment styles only apply when a Field is added to a HorizontalFieldManager. Fields added to a HorizontalFieldManager are ALWAYS aligned to the left.
Declare in the following format
HorizontalFieldManager horizontalContainer = new HorizontalFieldManager(Field.USE_ALL_WIDTH |DrawStyle.HCENTER);
Try like this in separate class and see the output:
HorizontalFieldManager hr=new HorizontalFieldManager(Field.FIELD_HCENTER);
hr.add(new LabelField("Black",Field.FOCUSABLE));
hr.add(new LabelField("Berry",Field.FOCUSABLE));
add(hr);
Enough;

How to increase row height in list field dynamically in Blackberry

I am displaying list of data which is coming from web service in list field.If the list item width is with in row width it is ok.But if the text length is more the text displaying in only one line.and last text is disappearing.How to display the large text in multiple lines by increasing row height in list field blackberry.
Thank You
you cannot resize the height of list field dynamically
try this
VerticalFieldManager vfm=new VerticalFieldManager();
HorizontalFieldManager hfm=new HorizontalFieldManager();
for(int i=0;i<data.length;i++)
{
hfm.add(/**ur data**/);
hfm.setMargin(top, right, bottom, left);
vfm.add(hfm);
}
this.add(vfm);

BlackBerry HorizontalFieldManager alignment

Horizontally, I want to display two bitmaps, and between them display a label field.
The code seems straightforward, but all the fields are added on the left side of the screen.
HorizontalFieldManager hfm = new HorizontalFieldManager();
callbmp = new BitmapField(ei.getBitmap(),Field.FOCUSABLE |BitmapField.FIELD_LEFT);
LabelField NAME = new LabelField("mylable", LabelField.FIELD_HCENTER);
mailbmp = new BitmapField(mail.getBitmap(),Field.FOCUSABLE|BitmapField.FIELD_RIGHT);
hfm.add(callbmp);
hfm.add(NAME);
hfm.add(mailbmp);
add(hfm);
Manager customManager = new Manager(0)
{
protected void sublayout(int width, int height) {
setPositionChild(
getField(0),
0,
0);
layoutChild(
getField(0),
getField(0).getPreferredWidth(),
getField(0).getPreferredHeight());
setPositionChild(
getField(1),
Graphics.getScreenWidth()/2 - getField(1).getPreferredWidth()/2,
0);
layoutChild(
getField(1),
getField(1).getPreferredWidth(),
getField(1).getPreferredHeight());
setPositionChild(
getField(2),
Graphics.getScreenWidth() - getField(2).getPreferredWidth(),
0);
layoutChild(
getField(2),
getField(2).getPreferredWidth(),
getField(2).getPreferredHeight());
setExtent(width, height);
}
};
customManager.add(new BitmapField(Bitmap.getBitmapResource("image1.png")));
customManager.add(new LabelField("Hello Alignment"));
customManager.add(new BitmapField(Bitmap.getBitmapResource("image2.png")));
HorizontalFieldManager lays out the fields left-to-right in the order in which they are added. The style bits for horizontal layout are ignored.
If you want left, right and center on a horizontal line, you'll need a custom manager.
This should be your requirement:
It can be done simply by subtracting the widths of the items you are adding on your horizontal field manager. By default the leftButton or the first item you add on the HFM will be added on left. Then you can add your label(userName) and the rightButton in the following way:
LabelField userName = new LabelField("MaheshBabu");
HorizontalFieldManager horizontalBar = new HorizontalFieldManager(USE_ALL_WIDTH|Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR);
horizontalBar.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
rightButton.setMargin(0, 0, 0, Display.getWidth()-rightButton.getPreferredWidth()-leftButton.getPreferredWidth()-userName.getPreferredWidth());
horizontalBar.add(leftButton);
horizontalBar.add(userName);
horizontalBar.add(rightButton);

How can I show a textbox on my BlackBerry application?

How can I add a textbox so a user can enter numeric values into my form? I need the borders of the textbox control to be visible at all time.
Thanks.
You should implement your own class, inherited from TextBox and override void paint(Graphics g) method.
Smth, like that, sorry i write from mobile:
public void paint(Graphics g)
{
// set color
g.setColor(0x555555);
// draw 100*100 rectangle
g.drawRect(0, 0, 100, 100);
// dont forget to invoke
super.paint(g);
}
If you dont want use overriding,
In OS 4.6+ you can use Border and BorderFactory classes (search in All Classes list).
// Each integer represents the amount of space between the box and border
// The four parameters of an XYEdge object represents each edge,
XYEdges thickPadding = new XYEdges(10, 10, 10, 10);
// Sample text field with a thick and solid rounded border
// and single solid colour background.
RichTextField simpleField = new RichTextField("Solid rounded border, solid background");
// Create border and background objects
Border roundedBorder = BorderFactory.createRoundedBorder(thickPadding, Border.STYLE_SOLID);
// Set the objects for use
simpleField.setBorder(roundedBorder);
// Add the field to the screen
add(simpleField);

Resources