Jump to content

Suggestion about dynamic colors from variables


goompas

Recommended Posts

Hello

I have question about dynamic setting colors . Is there possible that textfield or any other element have dynamic color? I dont think about conditional styles.

I have object that have fields value and color.

MyObject:

Double value;

Color color;

 

Now i wanna attach field color to property backcolor or forecolor of textfield. Is this possible? I know that i can make conditional style using filed color, but what when color is any rgb combination?

I see that JasperReport not allow set color using variables or fields, only string.

I can make this expression in conditional style

$F{bean}.getColor().equals("red") then in this conditional style set color to red, but what i should do when color is any rgb combination?

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

This is possible by modifying the background or foreground color of a report style after filling the report:

jasperPrint = JasperFillManager.fillReport(rptfile,parameters,ds);
Color userColor = new Color(R, G, B);
JRStyle[] styleList = jasperPrint.getStyles();
for (int j = 0; j < styleList.length; j++) {
        if (styleList[j].getName().equals("tableHeader")) {
                styleList[j].setBackcolor(userColor);
                jasperPrint.addStyle(styleList[j], true);
        } else if (styleList[j].getName().equals("formTitle")) {
                styleList[j].setForecolor(userColor);
                jasperPrint.addStyle(styleList[j], true);
        }
}

Let me know if you have any questions.
 

Link to comment
Share on other sites

  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...