Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin: Dynamically change a textfield's background color

Tags:

java

vaadin

How does one dynamically change a textfield's visual properties, say background color?

An example might be during a validation to modify the background color dependent on the value entered.

like image 756
Norman Shelley Avatar asked Jun 03 '26 08:06

Norman Shelley


1 Answers

In your war (this will be inside WebContent if you are using ecilpse) have a file in this path VAADIN/themes/customrunno/styles.css (asuming you are using runno as your theme)

With this content:

@import url(../runo/styles.css);

.my_bg_style {
     background: #99EE6B;  
}

In your init method:

setTheme("customruno"); // same as the folder folder under VAADIN/themes

change your textfield background:

textField.addStyleName("my_bg_style"); // same as in styles.css

to remove the style just do:

textField.removeStyleName("my_bg_style");
like image 160
David Hofmann Avatar answered Jun 04 '26 22:06

David Hofmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!