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

dkvidera

Members
  • Posts

    3
  • Joined

  • Last visited

dkvidera's Achievements

Newbie

Newbie (1/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Conversation Starter Rare

Recent Badges

0

Reputation

  1. We've had to deal with this too and have a few solutions. 1. If the number of columns is small and the same for all pages(data records) in the report, you can create the maximum number of column elements needed in the jrxml file and then set the unneeded ones to zero width and the needed ones to the correct width within the JasperReport object before sending it to the JasperFillManager. 2. If the number of columns is too cumbersome to create the maximum number of elements, you can create a subreport, load the jrxml, change the number of columns, compile the subreport, change the column element's width, and add it to the main report. Code:InputStream jasperIS = MyReport.class.getResourceAsStream("MySubreport.xml"«»); JasperDesign subDesign = JRXmlLoader.load(jasperIS); subDesign.setColumnCount(itemCount); int columnWidth = SUBREPORT_WIDTH / itemCount; subDesign.setColumnWidth(columnWidth); JasperReport subreport = JasperCompileManager.compileReport(subDesign); JRBand jb = subreport.getDetail(); JRElement je = jb.getElementByKey("theTextField"«»); je.setWidth(columnWidth); ... parameters.put("subreport", subreport); 3. If the number of columns changes for each page(data record) in the report, you will need to use a scriptlet. See my other post on "Changing report element properties in a scriptlet" for infor on how to do this. -doug
  2. Note: Once a fill element property is set, its new value remains for the rest of the report. So, if you modify a property for a special case of data, you will have to set it back for the normal cases. I used this logic for images that I wanted to shrink to fit the constraining space if too big, but not enlarge to fit if small enough. If the image was small enough, I changed the size and position of the JRFillImage element to center the image; otherwise, I set the element to its 'default' size and position and RetainShape scaling shrank it properly.
  3. Prior to version 1.1, you could easily change report element properties in a scriptlet by modifying the JRElement objects obtained through the JasperReport object. This no longer works because there is a parallel set of JRFillElement objects created by the JasperFillManager that now control the output. However, you can obtain and modify these JRFillElement objects in a scriptlet, if the report elements are in a group header or footer band. This does not work for elements in the predefined bands. The following code demonstrates how to do this: Code:public void beforeGroupInit(String groupName) throws JRScriptletException { if (GROUP_NAME.equals(groupName)) { JRFillGroup group = null; for (int g = 0; g < groups.length; g++) { if (GROUP_NAME.equals(groups[g].getName())) { group = groups[g]; break; } } JRFillXXX element = null; // group.getGroupHeader().getElementByKey(ELEMENT_KEY) doesn't work JRElement[] elms = group.getGroupHeader().getElements(); for (int e = 0; e < elms.length; e++) { if (ELEMENT_KEY.equals(elms[e].getKey())) { element = (JRFillXXX) elms[e]; break; } } element.setXXX(); ... } }
×
×
  • Create New...