View Full Version : How to change DateField width

11 Jun 2009, 5:00 AM
I am using a DateField and finding it difficult to control. There seems to be way too much space allocated to it on the form. I would like to set the width but this attribute seems to be completely ignored when it is rendered.

I am able to define a StyleName for the field and then I can adjust certain attributes via the CSS style sheet, however, the width is not one of them, suggesting that the width is generated into the html element.

Is there some way to adjust the width of this widget?


15 Jun 2009, 7:03 AM
The weird thing with this problem is that I can set an extra style on my form layout and this works. It allows me to override the border, so I can set it to red or green. Great. But I cannot override the size, width, maxlength.

Here's the java code:
FormLayout fl = new FormLayout();

And the style sheet:
.globalFilterDate {
border:0px solid red;
.globalFilterDate input {
border:0px solid green;
padding: 0px; margin: 0px;

Any ideas anyone?


15 Jun 2009, 7:04 AM
NB The border would be set to 1px in my above example during testing.

15 Jun 2009, 7:16 AM
You can use a FormData when adding it to your Panel.

FormPanel panel = new FormPanel();
DateField date = new DateField();
panel.add(date, new FormData("50%");

16 Jun 2009, 4:28 AM
Thank you fspab. I have sorted this out, largely due to your help. The final solution was indeed to specify a FormLayout for my FormPanel and then do as you say with the FormData:

m_Form.add(dateField, new FormData("90%"));