jraue
11 Jul 2008, 6:22 AM
Hi folks,
In our application we have a FormPanel with some TextFields. Some of them need to be capable to display beside the text a CheckBox in certain cases based on a boolean given in the constructor (imagine it a bit like bul processing in iTunes).
For that, I created a class ConfigurableTextField that derives from MultiField and contains a TextField and a CheckBox. When I add this to a FormPanel, I experience a strange effect: When entering text in multiple fields or clicking CheckBoxes or even on the form some TextFields disappear. You can easily see that in attached sample code.
Maybe I am doing something in my code or it is a bug. Either way, I am glad for hints on how to overcome that. NB: The effect only shows if the FormPanel is child to somthing else (HorizontalPanel in the sample code). If you add it to the ViewPort directly, everything works.
Thanks a lot for your help, guys. GXT rocks!
Joachim
public class ClientTest extends LayoutContainer implements EntryPoint {
protected static final boolean CONFIGURABLE = false;
protected static final int WIDTH_PROPERTY_PANEL = 420;
protected static final int WIDTH_LABEL = 150;
protected static final int WIDTH_FIELD = 210;
/**
* This is the entry point method.
*/
public void onModuleLoad() {
final Viewport viewport = new Viewport();
viewport.setLayout(new FillLayout());
final HorizontalPanel hp = new HorizontalPanel();
final FormPanel formPanel = new FormPanel();
formPanel.setHeading("My Form Panel");
formPanel.setFieldWidth(WIDTH_FIELD);
formPanel.setLabelWidth(WIDTH_LABEL);
formPanel.setLabelAlign(LabelAlign.RIGHT);
formPanel.setBorders(false);
formPanel.setFrame(true);
formPanel.setWidth(WIDTH_PROPERTY_PANEL);
final ConfigurableTextField d1TextField = addTextField(formPanel, "Value 1", 1);
final ConfigurableTextField d2TextField = addTextField(formPanel, "Value 2", 2);
final ConfigurableTextField d3TextField = addTextField(formPanel, "Value 3", 3);
final ConfigurableTextField d4TextField = addTextField(formPanel, "Value 4", 4);
hp.add(new Text("Imagine other elements here"));
hp.add(formPanel);
viewport.add(hp);
RootPanel.get().add(viewport);
}
protected ConfigurableTextField addTextField(final FormPanel parentContainer, final String fieldLabel, final int fieldId) {
final ConfigurableTextField textField = new ConfigurableTextField(fieldId, CONFIGURABLE);
textField.setFieldLabel(fieldLabel);
parentContainer.add(textField);
return textField;
}
class ConfigurableTextField extends MultiField<Field<?>> {
int fieldId;
TextField<String> textField;
CheckBox configCheckBox;
public ConfigurableTextField(final int fieldId, final boolean configurable) {
super();
this.fieldId = fieldId;
textField = new TextField<String>();
add(textField);
if (configurable) {
configCheckBox = new CheckBox();
add(configCheckBox);
}
}
public int getFieldId() {
return fieldId;
}
@Override
public void setWidth(final int width) {
if (configCheckBox != null) {
textField.setWidth(width - 30);
configCheckBox.setWidth(20);
} else {
textField.setWidth(width);
}
super.setWidth(width);
}
}
}
In our application we have a FormPanel with some TextFields. Some of them need to be capable to display beside the text a CheckBox in certain cases based on a boolean given in the constructor (imagine it a bit like bul processing in iTunes).
For that, I created a class ConfigurableTextField that derives from MultiField and contains a TextField and a CheckBox. When I add this to a FormPanel, I experience a strange effect: When entering text in multiple fields or clicking CheckBoxes or even on the form some TextFields disappear. You can easily see that in attached sample code.
Maybe I am doing something in my code or it is a bug. Either way, I am glad for hints on how to overcome that. NB: The effect only shows if the FormPanel is child to somthing else (HorizontalPanel in the sample code). If you add it to the ViewPort directly, everything works.
Thanks a lot for your help, guys. GXT rocks!
Joachim
public class ClientTest extends LayoutContainer implements EntryPoint {
protected static final boolean CONFIGURABLE = false;
protected static final int WIDTH_PROPERTY_PANEL = 420;
protected static final int WIDTH_LABEL = 150;
protected static final int WIDTH_FIELD = 210;
/**
* This is the entry point method.
*/
public void onModuleLoad() {
final Viewport viewport = new Viewport();
viewport.setLayout(new FillLayout());
final HorizontalPanel hp = new HorizontalPanel();
final FormPanel formPanel = new FormPanel();
formPanel.setHeading("My Form Panel");
formPanel.setFieldWidth(WIDTH_FIELD);
formPanel.setLabelWidth(WIDTH_LABEL);
formPanel.setLabelAlign(LabelAlign.RIGHT);
formPanel.setBorders(false);
formPanel.setFrame(true);
formPanel.setWidth(WIDTH_PROPERTY_PANEL);
final ConfigurableTextField d1TextField = addTextField(formPanel, "Value 1", 1);
final ConfigurableTextField d2TextField = addTextField(formPanel, "Value 2", 2);
final ConfigurableTextField d3TextField = addTextField(formPanel, "Value 3", 3);
final ConfigurableTextField d4TextField = addTextField(formPanel, "Value 4", 4);
hp.add(new Text("Imagine other elements here"));
hp.add(formPanel);
viewport.add(hp);
RootPanel.get().add(viewport);
}
protected ConfigurableTextField addTextField(final FormPanel parentContainer, final String fieldLabel, final int fieldId) {
final ConfigurableTextField textField = new ConfigurableTextField(fieldId, CONFIGURABLE);
textField.setFieldLabel(fieldLabel);
parentContainer.add(textField);
return textField;
}
class ConfigurableTextField extends MultiField<Field<?>> {
int fieldId;
TextField<String> textField;
CheckBox configCheckBox;
public ConfigurableTextField(final int fieldId, final boolean configurable) {
super();
this.fieldId = fieldId;
textField = new TextField<String>();
add(textField);
if (configurable) {
configCheckBox = new CheckBox();
add(configCheckBox);
}
}
public int getFieldId() {
return fieldId;
}
@Override
public void setWidth(final int width) {
if (configCheckBox != null) {
textField.setWidth(width - 30);
configCheckBox.setWidth(20);
} else {
textField.setWidth(width);
}
super.setWidth(width);
}
}
}