How to add check box to jrxml content.



I'm unable to find an option in ireport tool to add a check box to jrxml content.

my requirement is to add check box in jrxml content and at run time when I generate the pdf report out of jrxml,

I should be able to pass data which specifics whether the check box should be checked or not.

i.e (for instance for name field I could able to add a field and text box at same time at run time I'm able to pass the name while generating the report similarly I'm expecting same for my check box funtionlity).

please let us know the possible solution.

Any help is highly appreciated.




venkatgvr's picture
Joined: Dec 6 2011 - 7:16am
Last seen: 8 years 8 months ago

3 Answers:

One way is to layer a checked and unchecked box image on top of each other. Now use the print when expression to determine which image to display on the report.
svenn's picture
Joined: Mar 19 2007 - 5:57am
Last seen: 13 years 4 months ago



Thank you for your quick reply.

Please can you post some sample java code to  "determine which image to display on the report." at run time as post in below thread.

Right now I'm using below sample code to pass data to text field at runtime, where name and address are text fields specified in jrxml.

1) Java Code

2) Jrxml content

Any help is highly appreciated.


1)<========================Java Code ==============================>
String path = "D:\\\\dynamic_data";
HashMap map = new HashMap();
map.put("name", "tcs");
map.put("address", "hyd");
jasperReport = JasperCompileManager.compileReport(path+".jrxml");
jasperPrint = JasperFillManager.fillReport(jasperReport, map, 
JasperExportManager.exportReportToPdfFile(jasperPrint, path+new JREmptyDataSourc());
2)<=================JRXML Content======================>
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="" xmlns:xsi="" xsi:schemaLocation=" <a href=""" target="_blank">"</a> name=".jrxml" pageWidth="595" pageHeight="842" columnWidth="495" leftMargin="57" rightMargin="43" topMargin="43" bottomMargin="43">
	<queryString language="SQL">
	<field name="name" class="java.lang.String"/>
	<field name="address" class="java.lang.String"/>
	<variable name="name" class="java.lang.String"/>
		<band height="45" splitType="Stretch"/>
		<band height="45" splitType="Stretch"/>
		<band height="25" splitType="Stretch"/>
		<band height="73" splitType="Stretch">
				<reportElement x="106" y="12" width="62" height="15"/>
			<textField isBlankWhenNull="false">
				<reportElement x="224" y="12" width="72" height="15"/>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>
				<reportElement x="106" y="42" width="62" height="13"/>
			<textField isBlankWhenNull="false">
				<reportElement x="224" y="41" width="72" height="15"/>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{address}]]></textFieldExpression>
		<band height="45" splitType="Stretch"/>
		<band height="45" splitType="Stretch"/>
		<band height="45" splitType="Stretch"/>
		<band height="45" splitType="Stretch"/>
venkatgvr's picture
Joined: Dec 6 2011 - 7:16am
Last seen: 8 years 8 months ago

Another way is to use unicode:


  <field name="COLUMN_4" class ="java.lang.Boolean" />


<textFieldExpression class="java.lang.String">
     <![CDATA[$F{COLUMN_4} ? "u2611" : "u2610"]]>


Post Edited by lenalex at 08/26/2012 19:51
lenalex's picture
Joined: Jul 26 2012 - 1:37pm
Last seen: 8 years 2 weeks ago

This does not print a character with unicode u2611 (checkbox), but the string "u2611" itself; at least not with JR 5.5.0. I am using JasperStudio. I also noted that when I enter the "class=java.lang.String" in the textFieldExpression, the JasperStudio report designer automatically removes that attribute. I am using the ☐/☑ characters directly, not unicode encoded, works fine as well.

mathiaslin - 6 years 8 months ago

Need a \ character before the u to work

hacotjerome - 5 years 3 months ago

Exporting the jasper report to pdf with unicode is not printing the checkboxes.

manish.taneja01 - 1 year 5 months ago
show 1 more...

printing to pdf works, but you need to change the field font, eg. to DejaVu Sans

kojots - 4 months 6 days ago