It is simple to fix your issue - you should set isRemoveLineWhenBlank="true"
for the first textField (with ($F{country_id} != 1 ? "Gender" : null
epxression). In this case everything will be fine.
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="104" height="15" isRemoveLineWhenBlank="true"/>
<textElement>
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[($f{country_id} != 1 ? "Gender" : null )]]></textFieldExpression>
</textField>
I modified your template for check as
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Hide frame" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="country_id" class="java.lang.Integer"/>
<parameter name="gender" class="java.lang.String"/>
<title>
<band height="742">
<textField>
<reportElement positionType="Float" x="0" y="30" width="430" height="15" />
<textFieldExpression><![CDATA["First line"]]></textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="0" y="60" width="430" height="15" />
<textFieldExpression><![CDATA["Third line"]]></textFieldExpression>
</textField>
<frame>
<reportElement key="genderField" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="45" width="393" height="15" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" />
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="104" height="15" isRemoveLineWhenBlank="true" />
<textElement>
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[($P{country_id} != 1 ? "Gender" : null )]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="140" y="0" width="231" height="15" isRemoveLineWhenBlank="true" />
<textElement>
<font size="12" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[($P{country_id} != 1 ? $P{gender} : null )]]></textFieldExpression>
</textField>
</frame>
</band>
</title>
</jasperReport>
and it works like a charm:
You get the result above for example using combinations of parameters like:
In case using this values:
the reslut will be:
You can also simplify this fragment as at this example:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Hide frame" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="country_id" class="java.lang.Integer"/>
<parameter name="gender" class="java.lang.String"/>
<title>
<band height="742">
<textField>
<reportElement positionType="Float" x="0" y="30" width="430" height="15" />
<textFieldExpression><![CDATA["First line"]]></textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="0" y="60" width="430" height="15" />
<textFieldExpression><![CDATA["Third line"]]></textFieldExpression>
</textField>
<frame>
<reportElement positionType="Float" x="0" y="45" width="430" height="15" isRemoveLineWhenBlank="true" >
<printWhenExpression><![CDATA[$P{country_id} != 1 && $P{gender} != null]]></printWhenExpression>
</reportElement>
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="15" />
<textFieldExpression><![CDATA[$P{country_id} != 1 ? "Gender" : null]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="100" y="0" width="100" height="15" />
<textFieldExpression><![CDATA[$P{country_id} != 1 ? $P{gender} : null]]></textFieldExpression>
</textField>
</frame>
</band>
</title>
</jasperReport>
In this sample the isRemoveLineWhenBlank and printWhenExpression used only for frame element.
It is works the same as this example:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Hide frame" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="country_id" class="java.lang.Integer"/>
<parameter name="gender" class="java.lang.String"/>
<title>
<band height="742">
<textField>
<reportElement positionType="Float" x="0" y="30" width="430" height="15"/>
<textFieldExpression><![CDATA["First line"]]></textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="0" y="60" width="430" height="15"/>
<textFieldExpression><![CDATA["Third line"]]></textFieldExpression>
</textField>
<frame>
<reportElement positionType="Float" x="0" y="45" width="430" height="15" isRemoveLineWhenBlank="true"/>
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="15" isRemoveLineWhenBlank="true"/>
<textFieldExpression><![CDATA[$P{country_id} != 1 ? "Gender" : null]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="100" y="0" width="100" height="15" isRemoveLineWhenBlank="true"/>
<textFieldExpression><![CDATA[$P{country_id} != 1 ? $P{gender} : null]]></textFieldExpression>
</textField>
</frame>
</band>
</title>
</jasperReport>
The result will be the same, for example in case country_id == 1
:
UPDATE
You forgot to set isRemoveLineWhenBlank="true"
for frame with gender in your new snippet. After making this fix your new sample also works well in iReport 5.6.0. I replaced fields with parameters for testing purpose and change the order of frames to hide the frame with gender.
The jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Hide frame" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="country_id" class="java.lang.Integer"/>
<parameter name="gender" class="java.lang.String"/>
<parameter name="is_pd" class="java.lang.Boolean">
<defaultValueExpression><![CDATA[true]]></defaultValueExpression>
</parameter>
<parameter name="category_id" class="java.lang.Integer">
<defaultValueExpression><![CDATA[1]]></defaultValueExpression>
</parameter>
<title>
<band height="742">
<frame>
<reportElement key="govi" positionType="Float" stretchType="RelativeToTallestObject" x="124" y="129" width="403" height="17" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>
<staticText>
<reportElement x="0" y="0" width="141" height="15"/>
<text><![CDATA[Person with Disability ]]></text>
</staticText>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="140" y="0" width="245" height="15" isPrintWhenDetailOverflows="true"/>
<textElement textAlignment="Justified">
<font size="12" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$P{is_pd} ? "Yes" : "No"]]></textFieldExpression>
</textField>
</frame>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…