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;
Related
I want to align the Button on the same line as the Text Fields. The item alignment has been set to Alignment.CENTER, but as you can see from the image, the vertical centers of the TextFields are lower due to the label on top of them.
HorizontalLayout horizontalLayout = new HorizontalLayout();
horizontalLayout.setAlignItems(FlexComponent.Alignment.CENTER);
Div div = new Div(buttonAddPriceRange);
horizontalLayout.add(spanneVon, spanneBis, div);
layout.setAlignItems(Alignment.BASELINE); allows you to align items by the baseline, that is with the bottom.
HorizontalLayout hl = new HorizontalLayout(new TextField("hello"),
new Button("world"));
hl.setAlignItems(Alignment.BASELINE);
add(hl);
Check out the great video Master Vaadin VerticalLayout and HorizontalLayout - layouts in Vaadin Flow to learn more.
Try ...
horizontalLayout.setAlignItems(FlexComponent.Alignment.BASELINE);
I need to align a CheckboxField to the right of a fixed text (on Blackberry) like the "manage connections" dialog.
The code is:
final HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
hfm.add(new LabelField("Test me please", LabelField.ELLIPSIS | FIELD_LEFT | FIELD_VCENTER | USE_ALL_WIDTH));
cbx = new CheckboxField(null, false, FIELD_RIGHT | CheckboxField.NO_USE_ALL_WIDTH);
hfm.add(cbx);
I tried various combinations of "USE_ALL_WIDTH", "NO_USE_ALL_WIDTH" and similar flags, but I still can't get what I want: text all the way to the left, and check box all the way to the right.
If the label is set to USE_ALL_WIDTH, the checkbox disappears, and if it's not set, the checkbox is displayed near the text (not on the right side of the hfm).
Use following code,this will solve your problem.
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.USE_ALL_HEIGHT);
LabelField lblShow = new LabelField("Test me please ", Field.FIELD_LEFT);
CheckboxField cbShow = new CheckboxField("", false, CheckboxField.FIELD_RIGHT );
VerticalFieldManager vfmLeft = new VerticalFieldManager();
VerticalFieldManager vfmRight = new VerticalFieldManager(Field.USE_ALL_WIDTH);
vfmLeft.add(lblShow);
vfmRight.add(cbShow);
hfm.add(vfmLeft);
hfm.add(vfmRight);
add(hfm);
Use This style bit to align checkbox to right.
private static final long checkBoxStyle = 134217728;
add(new CheckboxField("test " , false, checkBoxStyle | USE_ALL_WIDTH));
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);
I added HorizontalFieldManager to screen with backgroundcolor and with specific width and height.And i added a labelField to hfm.But labelfield displaying at top in hfm.How can i adjust it to center.
Try This
LabelField.setMargin(Hfm height/2, 15, 0, 15);
Did you try to set the style of the labelfield to LabelField.Field_HCENTER? This should work for you
I want to know how to create VerticalFieldManager and i want to add some components also.
Couple of options:
A basic vertical field manager:
VerticalFieldManager vfm = new VerticalFieldManager();
// add your fields
vfm.add(new LabelField("First Label");
vfm.add(new LabelField("Second Label");
// etc
// then don't forget to add your vertical field manager to your screen
// assuming you're in the screen's constructor:
add(vfm);
The labels will appear top to bottom in the order you add them.
If you're going to add more fields than will fit vertically on a screen, you may want to make your manager scrollable:
VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
// the rest is the same as above
You can omit VERTICAL_SCROLLBAR if you don't want to see the up/down arrows.
But finally, if you just want a bunch of fields vertically on a screen, MainScreen by default uses a scrolling VerticalFieldManager as its delegate so you can just add fields directly and get the same effect:
class MyScreen extends MainScreen {
public MyScreen() {
add(new LabelField("Label 1");
add(new LabelField("Label 2");
// etc
}
}
Creation :
VerticalFieldManager vfm = new VerticalFieldManager();
Add different fields to it:
vfm.add(somefield);