Vaadin TextField readonly style

49 Views Asked by At

How can I change the style of a readonly TextField in Vaadin?

Now the default style after setting setReadOnly(true) is following:

enter image description here

I want this style with no border and an other backgroundcolor:

enter image description here

How can I achieve this?

1

There are 1 best solutions below

0
James On

you could try with this code for that particular text field you want to modify:

TextField textField = new TextField();
        textField.setReadOnly(true);

        // Remove border and set background color to gray
        textField.getElement().getStyle().set("border", "none");
        textField.getElement().getStyle().set("background-color", "gray");

it is worth noticing that if you want the whole application with that style please follow the documentation.
in there you can find how to customize all the text fields in your application.