Search code examples
gxtautosizeformpanel

autosize TextField labels in FormPanel in GXT


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!


Solution

  • 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);