如何在JasperReports中使用条件TextField?

Jon*_*nas 9 java conditional jasper-reports

我希望有一对TextFields取决于一个值.并且应根据空白空间调整"y"值.

当值为"0"I 时,我想隐藏TextField.

即我想在下面的jrxml代码中隐藏staticTexttextFieldif参数red是否相等"0"并将蓝色值向上移动:

  <staticText>
    <reportElement x="100" y="30" width="100" height="30"/>
    <text><![CDATA[Red items:]]></text>
  </staticText>
  <textField>
    <reportElement x="200" y="30" width="40" height="30"/>
    <textFieldExpression>
      <![CDATA[$P{red}]]>
    </textFieldExpression>
  </textField>

  <staticText>
    <reportElement x="100" y="60" width="100" height="30"/>
    <text><![CDATA[Blue items:]]></text>
  </staticText>
  <textField>
    <reportElement x="200" y="60" width="40" height="30"/>
    <textFieldExpression>
      <![CDATA[$P{blue}]]>
    </textFieldExpression>
  </textField>
Run Code Online (Sandbox Code Playgroud)

输出示例:

//if blue = 3 and red = 2    if blue = 3 and red = 0    if blue = 0 and red = 2
    Red items: 2               Blue items: 3              Red items: 2
    Blue items: 3    
Run Code Online (Sandbox Code Playgroud)

这些TextField将放在我的报告的末尾.我怎样才能做到这一点?

Boz*_*zho 12

<reportElement ...>
    <printWhenExpression><![CDATA[$P{red} == 0]]></printWhenExpression>
</reportElement>
Run Code Online (Sandbox Code Playgroud)

您可以使用iReport通过愉快的UI来修改它.