Floyd
Floyd

Reputation: 401

How to replace JRDesignBand in a JasperDesign?

I want to update my JasperReports version from 4.0.1 to the current 5.5.0.

My reports are generated, therefore I use a template-report. I have to replace the DetailBand, so I'm using getDetail() to get the band of my template-detail-section. After extracting some information and creating a new JRDesignBand newBand I'm using setDetail(newBand). Works!

With 5.5.0 this two methods are not available anymore. To get the band I can use something like this:

http://community.jaspersoft.com/questions/542111/jasper-reports-317-450-changes-jasperdesigngetdetail

But how to replace setDetail(newBand)??? I found this peace of code:

((JRDesignSection)jasperDesign.getDetailSection()).addBand(band);

But this adds the band, so I have 2 bands in my details-section. But I just need the new one...

Thank you!

Upvotes: 1

Views: 1601

Answers (1)

GenericJon
GenericJon

Reputation: 8986

You simply need to call removeBand(band) on the JRDesignSection to remove the old band. It shouldn't matter whether you do this before or after adding the new band, but it will leave you with just the new band present. E.g:

((JRDesignSection)jasperDesign.getDetailSection()).addBand(newBand);
((JRDesignSection)jasperDesign.getDetailSection()).removeBand(oldBand);

Upvotes: 1

Related Questions