views:

93

answers:

2

Hi,

I am writing a software where a process set text to a jtextarea. The jtextarea has a previously set width and a height. If input text is too long font size is changed so the whole text will fit with in the boundaries of the jtextarea.

And then I want to print this jtextarea. Printed version should also have exact properties like my user interface. I am using Jasper for this.

But the problem is I cant find a way to dynamically change font size in my generated report. Is there a way to do this? or please guide me to some good reference..

Thank you

+1  A: 

One possible way I found is to create a couple of fields with different font sizes on top of each other and create a different print expression for each of them.

You could check the length of the string in the field and only display the field that is appropriate for the string length.

Something like below might do if set as the print expression of your field.

($F{myField}.length() > 20 && $F{myField}.length() < 100) 

The expression will be true if the String length is greater than 20 but less than 100.

If you create several these fields it should be appropriate to handle different lengths.

Gordon
+1  A: 

You can take a look at the DynamicJasper library. It allows you to create reports programmaticaly. Even more, you can use your current report as a template, and handle the textfield's font size through DynamicJasper.

gedim