Drawing Checkboxes

Checkboxes in IS Tools is commonly rendered as a box, which is either selected/ticked or unselected/unticked. If checkboxes are needed in a PDF report the value has to be manipulated in the template , since there is no report element that will render a box in the current version of Jaspersoft Studio . But it is possible to make one in an easy way.

Checkboxes in the Excel format becomes TRUE (selected/ticked) or FALSE (unselected/unticked), while in the XML format has the value 1 (selected/ticked) or is without value (unselected/unticked). To use the preview-view which is based on the Excel format at the same time as the PDF report which uses the XML format it is possible to use the expression below for a field called Active.

new Boolean($F{Active}.toString().equalsIgnoreCase("true") || $F{Active}.toString().equals("1"))

The above returns true for both the preview and the PDF report . To draw a box, the box element is used. To render a checkbox, selected or not, it is possible to use the below XML in the source view .

<frame>
	<reportElement x="" y="" width="" height="" uuid=""/>
	<box padding="2"/>
	<frame>
		<reportElement x="0" y="0" width="12" height="12" uuid="">
			<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
		</reportElement>
		<box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
			<pen lineWidth="1.0"/>
			<topPen lineWidth="1.0"/>
			<leftPen lineWidth="1.0"/>
			<bottomPen lineWidth="1.0"/>
			<rightPen lineWidth="1.0"/>
		</box>
		<line>
			<reportElement x="2" y="7" width="2" height="2" uuid="">
				<printWhenExpression><![CDATA[new Boolean($F{Active}.toString().equalsIgnoreCase("true") || $F{Active}.toString().equals("1"))]]></printWhenExpression>
			</reportElement>
		</line>
		<line direction="BottomUp">
			<reportElement x="4" y="3" width="6" height="6" uuid="">
				<printWhenExpression><![CDATA[new Boolean($F{Active}.toString().equalsIgnoreCase("true") || $F{Active}.toString().equals("1"))]]></printWhenExpression>
			</reportElement>
		</line>
	</frame>
</frame>
Please note several attributes have been left blank (such as uuid), since these values need to be set in the template .

The outer frame is not necessary, but quite practical when copying or moving. In the above, two lines are used for the tickmark, and these are drawn/added conditionally using the expression above.

Report Checkbox
Checkbox in PDF

More tips