I am using iReport 3.5.2? to design a report. I have a subreport where I need to have a table.
To build the table I have drawn horizontal lines for rows. However I am not finding any option to make the line vertical so that I can make the columns.
Could anyone please suggest how to do it.
You can make your line Vertical of Horizontal as you like
By changing width and height properties of the line
For example
If you want to draw a Vertical Line
<line>
<reportElement x="0" y="0" width="1" height="30"/>
</line>
If you want to draw a Horizontal Line
<line>
<reportElement x="0" y="0" width="30" height="1"/>
</line>
line is bad decision, may be problems on page ending/begining
use
<style name="cell">
<box>
<pen lineWidth="1.0" lineStyle="Solid"/>
</box>
</style>
for your textField/staticText
Select line properties.Set width=1 ,height=value greater than 1
Related
I'm using iReport 3.7.6. (with no possibility of using a newer version).
I have a main report and a subreport. Subreport repeats multiple times and I need to set alternating background to subreports, but I need to show subreports one below each other so that they split when the new page starts, not showing them on page only if they fit.
This is what I want:
I tried multiple things but I cannot seem to get it to work.
I tried using frame and setting alternate row style and putting all the elements in that frame:
<style name="AlternateRowStyle" mode="Opaque">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT} % 2 == 0]]></conditionExpression>
<style backcolor="#E5E7E9"/>
</conditionalStyle>
</style>
but I get results like in this post: Splitting a band's background frame
Then I tried using background band (for simplicity, I just added frame with one color, so no alternation) but I have experienced difficulties in this approach too.
My subreport has only Detail and Background band to which I've set equal height and split type immediate.
Main report only has detail band (I simplified it).
Subreport snippet:
<background>
<band height="250" splitType="Immediate">
<frame>
<reportElement mode="Opaque" x="0" y="0" width="600" height="250" backcolor="#E5E7E9"/>
</frame>
</band>
</background>
<detail>
<band height="250" splitType="Immediate">
//content not important
</band>
</detail>
Main report snippet:
<detail>
<band height="660" splitType="Immediate">
<subreport>
<reportElement positionType="Float" x="0" y="0" width="600" height="250"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{objects})]]></dataSourceExpression>
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "subreport1.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
But this approach results in wierd behaviour: Background from subreport shows on each page of main report only once and only at the beginning of the page, no matter how many subreports are actually on one page of main report, like background is set to main report (shown on picture). I would like each report to have the background.
I'd appreciate any help.
This is the Report Output, that we are getting on applying single line in detail band, when the item name field gets Stretch with Overflow in iReport the single line remains and provides gap of the overflow area.
Any solution will be helpful.
Use the stretchType attribute on the reportElement that you need to adapt to the overflow of other elements (the line, the textField ecc). Set value RelativeToBandHeight or RelativeToTallestObject depending on what you like to achieve.
stretchTypes
NoStretch - The report element preserves its original specified
height.
RelativeToBandHeight - The report element adapts its height to
match the new height of the report section it is placed on, which has
been affected by stretch.
RelativeToTallestObject - Report elements
can be made to automatically adapt their height to fit the amount of
stretch suffered by the tallest element in the group that they are
part of.
If you are drawing a line es.
<line>
<reportElement stretchType="RelativeToBandHeight" x="1" y="0" width="1" height="20" uuid="2d923fed-08e1-4304-8b06-ef9894bd8181"/>
</line>
However I prefer not to draw lines but to use borders and padding on the textField in the report.
Example
<textField>
<reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="100" height="20" uuid="45c316a5-4e29-4247-acb5-2f551e9a8f47"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>
</textField>
My detail element is as follows:-
<detail>
<band height="22" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement uuid="a59a8d47-59cb-490e-953d-d4b1e2af52c0" x="0" y="0" width="191" height="20"/>
<box leftPadding="5" rightPadding="5"/>
<textElement verticalAlignment="Middle">
<font fontName="ARIALUNI" size="10" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{key}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement uuid="09798815-2a54-42db-963a-3f443a5fc1c2" x="191" y="0" width="500" height="20"/>
<box leftPadding="5" rightPadding="5"/>
<textElement verticalAlignment="Middle">
<font fontName="ARIALUNI" size="10" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
</textField>
</band>
</detail>
If I set band height="30", then the value of second correctly overflows but at same time extra white space is visible for rows where there is no overflow. With band height="22", no extra whitespace and also no overflows (which is a requirement). So can the height of band be set dynamically so that height increases when overflow takes place, otherwise it (height) maintains a low value (without extra-space).
This already happens automatically. If a band contains content that stretches, it will also stretch to accommodate that content. Or, as the JasperReports Ultimate Guide puts it:
"When stretchable text fields are present on a report section, the height of the report section
itself is affected by the stretch."
This makes sense when you think about when the report is filled. Theoretically you could always pass longer and longer data, making the text field stretch further and further. If the band height had to be set manually to accommodate this, you would be forever updating the design.
So what's the solution? Easy: Design everything at the minimum height, set fields to stretch if they need to, and don't worry about the band height.
What about the white space?
The white space you're seeing is probably due to the way space in the design is preserved at the end of a band. With your example, the band height is 22 pixels, but the content only fills a height of 20 pixels, leaving a 2 pixel row of white space at the bottom of the band. When you increase the band height to 30 pixels, without increasing the size of the content (I'm assuming this is the case), you will have created 10 pixels of white space.
The white space you leave in you design will be included in the filled report, repeated for each instance of the band and still included if the content stretches. So after your text field stretches to be 30 pixels tall, the band will stretch to 40 pixels to preserve the 10 pixels of white space.
I have a requirement to have a border that will encapsulate all the details + the column header in a report made in JasperReports + iReport. But if I try to draw a rect or a frame that goes in both the columns header, the details and column footer, I get an error saying that the element position is invalid.
I guess one option would be to use images (just like the good old HTML times without CSS...) but it would be a PITA since if a field overflow or if someone change the height or the width of a section, the image will have to change...
Any other alternatives?
Thanks.
To do this you can put frames into each of the bands, setting their size to fill the band completely. Then set the borders on the frames to replicate a border around all three bands, so the header has a border at the top, left and right; the footer has bottom, left and right; and the detail band has a border only on the left and right. See the example code below.
<columnHeader>
<band height="61" splitType="Stretch">
<frame>
<reportElement x="0" y="0" width="555" height="61"/>
<box>
<topPen lineWidth="2.0" lineStyle="Solid"/>
<leftPen lineWidth="2.0" lineStyle="Solid"/>
<rightPen lineWidth="2.0" lineStyle="Solid"/>
</box>
</frame>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<frame>
<reportElement x="0" y="0" width="555" height="125"/>
<box>
<leftPen lineWidth="2.0" lineStyle="Solid"/>
<rightPen lineWidth="2.0" lineStyle="Solid"/>
</box>
</frame>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch">
<frame>
<reportElement x="0" y="0" width="555" height="45"/>
<box>
<leftPen lineWidth="2.0" lineStyle="Solid"/>
<bottomPen lineWidth="2.0" lineStyle="Solid"/>
<rightPen lineWidth="2.0" lineStyle="Solid"/>
</box>
</frame>
</band>
</columnFooter>
The result should look like this:
you can use the background-band on which you draw a rectangle for that purpose .
Using a background band with a Frame or Rectangle seems to work best, although, if the first and subsequent pages have different Header Elements, sizing the Frame/Rectangle can be a bit tricky.
One way round this is to add a Frame/Rectangle on the any Title, Header and Footer bands,
which is Opaque/White and sent to the Back. This will obscure the Background Image.
This means that it will just be show through for the Detail Band, so the Header and Footer Frame may need a bottom/top border depending on what you want.
(I found that the problem with using a Frame in the Detail band with just side borders doesn't quite work as sometime the repeated detail band does not fill each page, so gaps are left in the borders at the sides)
Click your jasper report.
Go to basic Elements.
choose rectangle.
I need to have a staticText to float below another element with variable height. I'm taking a sample from the book JasperReports for Java Programmers. It says that it's possible to do it. The difference with my sample is that I use a hard coded string in textFieldExpression, they use a $F{} field.
<textField isStretchWithOverflow="true" hyperlinkType="None">
<reportElement x="0" y="0" width="100" height="24"/>
<box>
<pen lineWidth="0.5" lineStyle="Solid"/>
</box>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["jjjjjjjjjjj oooooooooo uuuuuuuuuu aaaaaaaaaa xxxxxxxxx u ttttt"]]></textFieldExpression>
</textField>
<staticText>
<reportElement positionType="Float" x="0" y="25" width="500" height="30"/>
<box>
<pen lineWidth="0.5" lineStyle="Solid"/>
</box>
<textElement/>
<text><![CDATA[ This staticText element has a positionType of "Float" ppp ]]></text>
</staticText>
It says that when you use positionType="Float", the y attribute is ignored, because the staticText is positioned below the textField. This appears to work, BUT... is it possible they are BS'ing me? The textField has y=0 and height=24. The staticText has y=25. Coincidence? If I change the staticText's y, it is obvious that it isn't ignored: the element is positioned wherever I tell it to. There's no floating!!!
Quote from the book:
As we can see, setting the positionType attribute of <reportElement> to Float made JasperReports ignore the y position of the <staticText> element, which was pushed down by the stretched <textField> element.
No, we don't see how it is being ignored because y=25 is where we expected it!
Does positionType="Float" work for staticText at all?
Thanks!
My understanding of the floating nature is that the floating object will move down if necessary, but if the previous object is smaller than expected, it doesn't move up.
I don't recall having any problems with floating objects not actually floating down when necessary, whether they be static text or text fields.
On another note, if you find a text field works, you can use it to display static text by putting your text in quotes in the text field value (making it a Java object).
This answer applies (different elements, same situation).
One thing I didn't take right from the book's sample is that the textField's declared height (24) is less than the actual height when the element is stretched. So, y="25" on the staticText would map above its actual position; the element is actually floated down!