PDA

View Full Version : Incorrect Label and field alignment and field width



sz_146
2 Apr 2009, 3:38 AM
I have the following form which displays Address fields. I have 2 issues :

The labels and fields are not align i.e. the Labels appear slightly above the fields which look awkward
I can't set the field width on particular fields e.g. Postcode and County. I have tried all sorts of setWidth setSize etc.

protected ContentPanel getAddressPanel(){

ContentPanel addressData = new ContentPanel();
FormLayout fl = new FormLayout();
fl.setLabelAlign(LabelAlign.RIGHT);
addressData.setLayout(fl);
addressData.setCollapsible(true);
addressData.setHeading("Address " + (getAddressCount() + 1) );

String[] labels = {"Line 1", "Line 2", "Line 3", "Town/City", "County", "Postcode"};
renderAddressFields(labels, addressData);

return addressData;

}

private void renderAddressFields(String[] labels, LayoutContainer cont){

for(String s : labels){
TextField<String> txtField = new TextField<String>();
txtField.setFieldLabel(s);

// Need the field width to be 8 chars setWidth and setSize doesn't work
if(s.equals("Postcode")){
txtField.setMaxLength(8);
}

cont.add(txtField);
addressFieldsHash.put(getNextAddressFieldID(), txtField);
}
}

sdc
10 Apr 2009, 6:18 AM
I also wanted to set the width on a particular field but in a FormPanel instead of a ContentPanel.
I did :

ComponentHelper.setLayoutData(formPanel, new FormData(350,0));But it would be nice to get an official answer.

sz_146
14 Apr 2009, 12:19 AM
I got the width problem fixed using CSS for individual fields like this :



txtField.setStyleName("style-name");
However I havn't tried the alignment with it yet. I think CSS may be the answer to that too.

I think you can set default field width using the FormLayout.setDefaultWidth() if your aim is to set one width for all fields. FormPanel uses FormLayout by default.