15.7. Working with Border and Background Styles
Problem
You want to apply styles to the border and background of a component or components.
Solution
Use the backgroundColor, borderColor, or borderStyle style property.
Discussion
You can set the background and border colors for components using the appropriate styles. For the background, just assign a value to the backgroundColor property. For example, the following code applies a red background to a list named clProducts:
clProducts.setStyle("backgroundColor", "red");The background color is one of the styles that does not inherit properly when you apply it globally. That means that it will not take effect for some types of components if you use the following line of code:
_global.style.setStyle("backgroundColor", "red");It does inherit correctly for some types of components, such as the combo box, numeric stepper, window, date chooser, and date field. However, it does not properly inherit for other component types, such as list, text input, and text area. One solution is to apply the styles to each component instance, or perhaps each component class. However, that could prove rather unnecessarily tedious. Instead, as a workaround, you can apply the style settings globally as normal. But in addition, define the class style objects for the necessary classes. By just defining the class style object, the global styles will then inherit properly. The following is an example in which you can apply the backgroundColor style globally. If your ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access