Jump to content
JasperReports Library 7.0 is now available ×

Changing Element Properties at Runtime


2004 IR Help

Recommended Posts

By: Andy Mitchell - amitchel

Changing Element Properties at Runtime

2005-02-07 17:48

I'd to change the x-coord and width of an element at runtime. The trick with this one is that each row has different x-coord and widths.

 

Here's an example. Let's say I have a report with 2 rows. Each row has a subreport with between three and six rows. I lay out the subreport data horizontally (either using report columns or using a scriptlet to add them to variables).

 

Let's say the width of the report is 200 pixels. The first record of the master report has four elements in the subreport. I'd like each element to be 50 pixels width ( 200 pixels / 4 elements ). Element 1 would start at pixel 1, element 2 at pixel 51 etc.

 

The second record of the master report has five elements in the subreport. I'd like each element to be 40 pixels in width ( 200 pixels / 5 elements ). Element 1 would start at pixel 1, element 2 at pixel 41 etc.

 

Here's what have I thought of:

- print when expression : this does not change the width or spacing.

- scriptlet : I can set the value of a variable, but I don't have access to the underlying elements.

- built in variables : there are built-in variables for page_count, column_count, the connection, the scriptlet etc. There's no built-in that helps me get to the underlying elements.

- alter design : looked at AlterDesignApp.java. This idea would allow me to change the element before running it. But it's a global change. I could change the first row to 50 pixels, but that change would affect the second row also.

 

Is there something I'm overlooking? Is there a way to get the element at runtime and switch it for each detail?

 

Thanks in advance...

 

 

 

 

By: Andy Mitchell - amitchel

RE: Changing Element Properties at Runtime

2005-02-14 09:29

Just thought I'd close this out. I could find out a way to solve it dynamically. I changed the underlying code to add in the JRBaseFiller as a parameter. That got me to the JRBand and eventuall the JRElement. In the scriptlet, I changed the width and x-coordinate of the elements. But the layout properties couldn't be changed dynamically. The elements were set on the band in their positions. I looked a little while longer and then guessed it couldn't be done without radical changes to the code.

 

So, I solved it by creating a bunch of elements. I know that I'll have between 3 and 6 detail records, so I created a layer of elements for 3 records, a layer for 4 elements etc. I hide the other layers using printWhenExpression.

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