How to set a background color of a Table Cell using iText?

匆匆过客 提交于 2019-11-29 23:25:44

Lots of options.

BaseColor color = new BaseColor(red, green, blue); // or red, green, blue, alpha
CYMKColor cmyk = new CMYKColor(cyan, yellow, magenta, black); // no alpha
GrayColor gray = new GrayColor(someFloatBetweenZeroAndOneInclusive); // no alpha

There's also pattern colors and shading colors, but those are Much Less Simple.

JAM

Posting, in hopes someone else will find this response useful.

It seems one can create a new BaseColor from WebColor as:

BaseColor myColor = WebColors.GetRGBColor("#A00000");

Which then can be added as a background as:

cell.setBackgroundColor(myColor);
Tony Chen

Try this:
cell.setBackgroundColor(new BaseColor(226, 226, 226));
or:
cell.setBackgroundColor(WebColors.getRGBColor("#E2E2E2")); deprecated

One more solution is:

public static String mColor = "#aa8cc5";
int aa = Integer.parseInt(mColor,16); // base 16
int colorArr = Color.rgb(Color.red(aa),Color.green(aa),Color.blue(aa));
cell1.setBackgroundColor(new BaseColor(colorArr));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!