Jump to content
We've recently updated our Privacy Statement, available here ×

How use colors of fields from DB


goompas

Recommended Posts

Hello

I have in DB colors of textfields from my reports. How can i set colors text of textfields(type Double) using colors from DB ?

I know that i can use styled text but then i must have textfield type String, but i need textfield type Double to export report to xls and then using it.

Can i edit report after filling to jasperPrint but before generate xls? If yes, then i can check field color and set color of textfield.

There is dynamic numbers of rows and not all haved that same color.

I have field that stored color.

Row 1-20 red

Row 21-23 - oragne

etc

Colors are defined by user and stored in DB.

I see AlterDesign sample, but it show how edit report structure from jrxml and then i have one color for all rows.



Post Edited by goompas . at 04/01/09 11:01
Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

 

Retrieve the colors from report query and apply the corresponding color to the text field by using styles.....

 

If am not wrong we cant edit the report after filling the report, before generating the report in xls format as the same JasperPrint object is used to export the report.

 

DNV Srikanth.



Post Edited by Srikanth DNV at 04/01/09 11:41
Link to comment
Share on other sites

Primary:

I need change dynamic color of textfiled that type is java.lang.Double(BigDecimal, only number not String). These color i get from datasorce as field.

Raport structure is like this:

A B C D E F G ...

1 1 1 1 1 1 1 1 ...

2 2 2 2 2 2 2 2 ...

3 3 3 3 3 3 3 3 ...

..

Every point can have different color, that is stored in object from field.

I cant i conditional style setting forecolor use this formula

$F{value}[0].getColor()

It can be only like this: #33FF33

Im only need set dynamicly forecolor or backcolor in conditional style and this color cant be static because i get it together with field.

 

I try too this:

 List jpages = jasperPrint.getPages();
            System.out.println("pages size " + jpages.size());


            for (int i = 0; i < jpages.size(); i++)
            {
                JRPrintPage page = (JRPrintPage) jpages.get(i);
                
                List elementy = page.getElements();
                System.out.println("lista elementow strona " + i + " elementow " + elementy.size());
                for (int j = 0; j < elementy.size(); j++)
                {
                    //  JRPrintElement element = (JRPrintElement) elementy.get(j);
                    System.out.println("page " + i + " element " + j);
                    JRTemplatePrintText text = (JRTemplatePrintText) elementy.get(j);
                                    
                    System.out.println("get forecolor " + text.getForecolor());
                    System.out.println("text backcolor"+text.getBackcolor());

                    Color color=new Color(255,0,255);
                    text.setMode(JRElement.MODE_OPAQUE);

                    System.out.println("color "+color);
                    text.setForecolor(color);
                    text.setBackcolor(color);
                    System.out.println("po zmianie forecolor "+text.getForecolor());
                    System.out.println("po zmianie backcolor "+text.getBackcolor());
}
}

but this

                    text.setForecolor(color);
                    text.setBackcolor(color);

dont work for me, its dont change color.

And here is another question: can i from jasperPrint get elements of report rom by key? Like getElementByKey() ?

sorry for my english but i think you understand :)



Post Edited by goompas . at 04/02/09 08:55
Link to comment
Share on other sites

Thx for answer

Yes i know that and try that, but i dont wanna have numbers as Strings and styled text dont work in excel. I need have it as Double, Integer, Bigdecimal(numbers) because later i export raport to xls and need that excel see it as numbers, not strings.



Post Edited by goompas . at 04/03/09 06:32
Link to comment
Share on other sites

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...