0
votes

using GXT 2.1.1 i have a number of FormPanel instances, all with the default FormLayout layout. each form contains a number of TextField instances, with the host form automatically placing a label for each text field. the trouble is that in some cases, label text is quite small, placing a rather large space between a label and it respective text field. in other cases, label text is too large, forcing its contents to wrap. what i would like to do is somehow autosize all the labels to the width of the widest label on that form.

FormLayout does have a setLabelWidth(int pixel) function, but its argument must be in pixels. i was thinking of using TextField.getFieldLabel() to retrieve the label text, yet i do not know how to convert it to pixels.

thank you for your time!

2

2 Answers

0
votes

There is no Functionality to autosize textfield label in form panel.but you can set maximum size as follows

 FormPanel formPanel = new FormPanel();  
 formPanel.setBodyBorder(false);
 formPanel.setButtonAlign(HorizontalAlignment.CENTER);

    FormLayout layout = new FormLayout();  
    layout.setLabelAlign(LabelAlign.LEFT);
    layout.setLabelWidth(200);//Here you can set maximum size of your label
    formPanel.setLayout(layout);
0
votes

don't know if this is really the answer to the question, but i hope that it perhaps helps someone down the road. i really liked the way GWT's FlexTable behaved with respect to the label resize i was looking for. however, GXT treats GWT's Widget instances as a WidgetComponent, which does not get traversed for nested Field instances when placed in a FormPanel. so my final solution was to extend GXT's FormPanel and overwrite its getFields() and getChildFields() functions, with the latter's logic looking for WidgetComponent instances in addition to Container instances:

  for (Component comp : c.getItems()) {
    if (comp instanceof Field) {
      fields.add((Field<?>) comp);
    }
    else if (comp instanceof WidgetComponent) {
       if (((WidgetComponent) comp).getWidget() instanceof FlexTable) {

             // logic to retrieve Field instances from FlexTable

       }
    }
    else if (comp instanceof Container) {
      getChildFields((Container<Component>) comp, fields);
    }
  }

to complement this logic, i also had to extend FlexTable to allow for setting and retrieving Field instances.