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

Can't set element widths in 1.1 scriptlets


Recommended Posts

By: Douglas Kvidera - dkvidera

Can't set element widths in 1.1 scriptlets

2006-01-05 11:46

In 1.0, I could do:

...

public void afterReportInit() throws JRScriptletException {

JasperReport jr = (JasperReport) getParameterValue("mainReport");

JRBand jb = jr.getColumnHeader();

JRElement je = jb.getElementByKey("headerTitle");

je.setWidth(width);

...

 

and dynamically set the width of an element. The code runs in 1.1.1, but has no effect. It doesn't work to run the same code in any of the other before/after methods either.

 

I could compile on-the-fly using a JasperDesign. In fact, I'm already doing this for simple subreports--setting their column count and width. Setting subreport element widths' in the main report's scriptlet's afterReportInit method works fine (but not in a subreport's scriptlet).

 

Any suggestions that would solve this and avoid compiling the main report would be appreciated.

 

(I know crosstabs might work, but am waiting for support in iReport)

 

 

By: Douglas Kvidera - dkvidera

RE: Can't set element widths in 1.1 scriptlet

2006-01-09 13:02

Thanks. It works fine to change the widths through the JasperReport before calling JasperFillManager.fillReport().

 

This is used to solve the common problem of dynamically setting the number of columns for two cases:

 

Case 1 - a small, maximum number of columns is known

- create the maximum number of columns in the .jrxml file, compile and load it

- set the unneeded elements' widths to zero and the needed ones' widths to fill the space

 

Case 2 - a large or unknown maximum number of columns

- create a subreport

- load the subreport as a JasperDesign and set the column count and width accordingly then compile it dynamically using JasperCompileManager.compileReport()

 

 

By: Lucian Chirita - lucianc

RE: Can't set element widths in 1.1 scriptlet

2006-01-06 08:35

This doesn't work in 1.1 because the widths of all elements are copied when the filler is created. Prior to 1.1, the widths were resolved from the elements in the JasperReport object. We thought no one would alter element coordinates during the fill.

 

Is it possible for you to change the widths before starting the fill process?

 

We could provide a fix to ensure that the behaviour is restored, but it might take some time.

 

Regards,

Lucian

 

 

By: Douglas Kvidera - dkvidera

RE: Can't set element widths in 1.1 scriptlet

2006-02-27 07:55

This issue has resurfaced with reports that present data as multiple, horizontal stacked-bar charts. This was done by setting the width and position of testField elements in the scriptlet. It can't be done before the fillReport call because the values must change for each record in the dataset.

 

Is there any way to access the corresponding fill objects in the scriptlet to change the values there?

 

 

 

 

By: Douglas Kvidera - dkvidera

RE: Can't set element widths in 1.1 scriptlet

2006-03-15 10:41

I attempted a different solution which dynamically creates the stacked bars as java.awt.Image objects in the scriptlet. However, in order to get decent resolution, the images are drawn large and scaled down. This results in a PDF report file that is over 4MB per page! This will not work for a several-page report delivered on-line.

 

My next attempt will likely be to create a custom element. Any help beyond "study the source" would be appreciated.

 

Until then, I'm stuck with version 1.0.0.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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