简体   繁体   English

Vaadin 将组件颜色设置为十六进制或整数或 rgb

[英]Vaadin set component color to hex or int or rgb

I am currently messing about with Vaadin.我目前正在与 Vaadin 混为一谈。

I see that that I can change background color of eg button like so:我看到我可以像这样更改例如按钮的背景颜色:

cButton.getStyle().set("background","red");

But if I want to set a specific color like this one: #EAB251.但是如果我想设置一个像这样的特定颜色:#EAB251。 How can it be done?怎么做到呢?

This color could change depending on what the user chooses in an RGB-/HEX-/INT-color picker.该颜色可能会根据用户在 RGB-/HEX-/INT-颜色选择器中的选择而改变。

You can use any valid CSS value for the property.您可以为该属性使用任何有效的 CSS 值。 So cButton.getStyle().set("background", "#EAB251") and cButton.getStyle().set("background", "rgb(234, 178, 81)") should work.所以cButton.getStyle().set("background", "#EAB251")cButton.getStyle().set("background", "rgb(234, 178, 81)")应该可以工作。 In fact, the line of code you posted works because red is a CSS color name.事实上,您发布的代码行有效,因为red是 CSS 颜色名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM