nyklogistics
8 Jul 2009, 7:38 PM
First question, what is the layout I should used to fit the field width in the form layout. I have tried to use FitLayout, but it does not work. And I have tried to use VBoxLayout and HBoxLayout, it does not render the component properly.
And I've tried to set the component width with 100% in a FlowLayout, but it does not fit the field width of the FormPanel too.
private void createForm1() {
FormPanel simple = new FormPanel();
simple.setHeading("Simple Form");
simple.setFrame(true);
simple.setWidth(500);
simple.setFieldWidth(350);
simple.setLabelWidth(150);
TextField<String> firstName = new TextField<String>();
firstName.setValue("first name");
firstName.setWidth("100%");
TextField<String> middleName = new TextField<String>();
middleName.setValue("middle name");
middleName.setWidth("100%");
ComboBox<BaseModelData> lastName= new ComboBox<BaseModelData>();
lastName.setStore(new ListStore<BaseModelData>());
lastName.setWidth("100%");
LayoutContainer w = new LayoutContainer(new FlowLayout());
w.add(firstName, new FlowData(new Margins(0, 0, 5, 0)));
w.add(middleName, new FlowData(new Margins(0, 0, 5, 0)));
w.add(lastName, new FlowData(new Margins(0)));
AdapterField name = new AdapterField(w);
name.setResizeWidget(true);
name.setFieldLabel("Name");
simple.add(name, formData);
TextField<String> email = new TextField<String>();
email.setFieldLabel("Email");
email.setAllowBlank(false);
simple.add(email, formData);
List<Stock> stocks = TestData.getStocks();
Collections.sort(stocks, new Comparator<Stock>() {
public int compare(Stock arg0, Stock arg1) {
return arg0.getName().compareTo(arg1.getName());
}
});
ListStore<Stock> store = new ListStore<Stock>();
store.add(stocks);
ComboBox<Stock> combo = new ComboBox<Stock>();
combo.setFieldLabel("Company");
combo.setDisplayField("name");
combo.setTriggerAction(TriggerAction.ALL);
combo.setStore(store);
simple.add(combo, formData);
DateField date = new DateField();
date.setFieldLabel("Birthday");
simple.add(date, formData);
TimeField time = new TimeField();
time.setFieldLabel("Time");
simple.add(time, formData);
Slider slider = new Slider();
slider.setMinValue(40);
slider.setMaxValue(90);
slider.setValue(60);
slider.setIncrement(1);
slider.setMessage("{0} inches tall");
final SliderField sf = new SliderField(slider);
sf.setFieldLabel("Size");
simple.add(sf, formData);
CheckBox check1 = new CheckBox();
check1.setBoxLabel("Classical");
CheckBox check2 = new CheckBox();
check2.setBoxLabel("Rock");
check2.setValue(true);
CheckBox check3 = new CheckBox();
check3.setBoxLabel("Blue");
CheckBoxGroup checkGroup = new CheckBoxGroup();
checkGroup.setFieldLabel("Music");
checkGroup.add(check1);
checkGroup.add(check2);
checkGroup.add(check3);
simple.add(checkGroup, formData);
Radio radio = new Radio();
radio.setName("radio");
radio.setBoxLabel("Red");
radio.setValue(true);
Radio radio2 = new Radio();
radio2.setName("radio");
radio2.setBoxLabel("Blue");
RadioGroup radioGroup = new RadioGroup("test");
radioGroup.setFieldLabel("Favorite Color");
radioGroup.add(radio);
radioGroup.add(radio2);
simple.add(radioGroup, formData);
TextArea description = new TextArea();
description.setPreventScrollbars(true);
description.setFieldLabel("Description");
simple.add(description, formData);
Button b = new Button("Submit");
simple.addButton(b);
simple.addButton(new Button("Cancel"));
simple.setButtonAlign(HorizontalAlignment.CENTER);
FormButtonBinding binding = new FormButtonBinding(simple);
binding.addButton(b);
vp.add(simple);
}
http://img7.imageshack.us/img7/4873/99333316.png
Besides, please consider the my question in http://extjs.com/forum/showthread.php?t=73340 together which is relevant to the AdapterField.
I cannot see any example of using AdapterField in the demo. I think it is a valuable widget for building a more advanced form.
And I've tried to set the component width with 100% in a FlowLayout, but it does not fit the field width of the FormPanel too.
private void createForm1() {
FormPanel simple = new FormPanel();
simple.setHeading("Simple Form");
simple.setFrame(true);
simple.setWidth(500);
simple.setFieldWidth(350);
simple.setLabelWidth(150);
TextField<String> firstName = new TextField<String>();
firstName.setValue("first name");
firstName.setWidth("100%");
TextField<String> middleName = new TextField<String>();
middleName.setValue("middle name");
middleName.setWidth("100%");
ComboBox<BaseModelData> lastName= new ComboBox<BaseModelData>();
lastName.setStore(new ListStore<BaseModelData>());
lastName.setWidth("100%");
LayoutContainer w = new LayoutContainer(new FlowLayout());
w.add(firstName, new FlowData(new Margins(0, 0, 5, 0)));
w.add(middleName, new FlowData(new Margins(0, 0, 5, 0)));
w.add(lastName, new FlowData(new Margins(0)));
AdapterField name = new AdapterField(w);
name.setResizeWidget(true);
name.setFieldLabel("Name");
simple.add(name, formData);
TextField<String> email = new TextField<String>();
email.setFieldLabel("Email");
email.setAllowBlank(false);
simple.add(email, formData);
List<Stock> stocks = TestData.getStocks();
Collections.sort(stocks, new Comparator<Stock>() {
public int compare(Stock arg0, Stock arg1) {
return arg0.getName().compareTo(arg1.getName());
}
});
ListStore<Stock> store = new ListStore<Stock>();
store.add(stocks);
ComboBox<Stock> combo = new ComboBox<Stock>();
combo.setFieldLabel("Company");
combo.setDisplayField("name");
combo.setTriggerAction(TriggerAction.ALL);
combo.setStore(store);
simple.add(combo, formData);
DateField date = new DateField();
date.setFieldLabel("Birthday");
simple.add(date, formData);
TimeField time = new TimeField();
time.setFieldLabel("Time");
simple.add(time, formData);
Slider slider = new Slider();
slider.setMinValue(40);
slider.setMaxValue(90);
slider.setValue(60);
slider.setIncrement(1);
slider.setMessage("{0} inches tall");
final SliderField sf = new SliderField(slider);
sf.setFieldLabel("Size");
simple.add(sf, formData);
CheckBox check1 = new CheckBox();
check1.setBoxLabel("Classical");
CheckBox check2 = new CheckBox();
check2.setBoxLabel("Rock");
check2.setValue(true);
CheckBox check3 = new CheckBox();
check3.setBoxLabel("Blue");
CheckBoxGroup checkGroup = new CheckBoxGroup();
checkGroup.setFieldLabel("Music");
checkGroup.add(check1);
checkGroup.add(check2);
checkGroup.add(check3);
simple.add(checkGroup, formData);
Radio radio = new Radio();
radio.setName("radio");
radio.setBoxLabel("Red");
radio.setValue(true);
Radio radio2 = new Radio();
radio2.setName("radio");
radio2.setBoxLabel("Blue");
RadioGroup radioGroup = new RadioGroup("test");
radioGroup.setFieldLabel("Favorite Color");
radioGroup.add(radio);
radioGroup.add(radio2);
simple.add(radioGroup, formData);
TextArea description = new TextArea();
description.setPreventScrollbars(true);
description.setFieldLabel("Description");
simple.add(description, formData);
Button b = new Button("Submit");
simple.addButton(b);
simple.addButton(new Button("Cancel"));
simple.setButtonAlign(HorizontalAlignment.CENTER);
FormButtonBinding binding = new FormButtonBinding(simple);
binding.addButton(b);
vp.add(simple);
}
http://img7.imageshack.us/img7/4873/99333316.png
Besides, please consider the my question in http://extjs.com/forum/showthread.php?t=73340 together which is relevant to the AdapterField.
I cannot see any example of using AdapterField in the demo. I think it is a valuable widget for building a more advanced form.