Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 删除水平空白_Java_Jasper Reports - Fatal编程技术网

Java 删除水平空白

Java 删除水平空白,java,jasper-reports,Java,Jasper Reports,我在子报表上有一个文本字段和一个图像字段,如果没有图像,我想水平移动文本字段的内容 如果没有图像,我想将textField替换为image。试试这个 public JasperDesign setImage(Boolean isImageAvailable) throws JRException { JasperDesign jasperDesign = new JasperDesign(); jasperDesign.setName("NoXmlDesignReport"); j

我在
子报表上有一个
文本字段
和一个
图像
字段,如果没有图像,我想水平移动文本字段的内容

如果没有图像,我想将
textField
替换为image。

试试这个

public JasperDesign setImage(Boolean isImageAvailable) throws JRException {
  JasperDesign jasperDesign = new JasperDesign();
  jasperDesign.setName("NoXmlDesignReport");
  jasperDesign.setPageWidth(595);
  jasperDesign.setPageHeight(842);
  jasperDesign.setColumnWidth(515);
  jasperDesign.setColumnSpacing(0);
  jasperDesign.setLeftMargin(40);
  jasperDesign.setRightMargin(40);
  jasperDesign.setTopMargin(20);
  jasperDesign.setBottomMargin(20);
  JRDesignBand band = new JRDesignBand();
  band.setHeight(200);

  JRDesignTextField textField = new JRDesignTextField();
  textField.setX(350);//Your desired x position when image is not available.
  textField.setY(0);//Your desired y position when image is not available.
  textField.setWidth(100);
  textField.setHeight(20);
  textField.setStyle(normalStyle);
  textField.setStretchWithOverflow(true);
  textField.setPositionType(PositionTypeEnum.FLOAT);
  textField.setBlankWhenNull(true);
  JRDesignExpression expression = new JRDesignExpression();
  expression.setText("$F{" + fieldName + "}");
  textField.setExpression(expression);

  if(isImageAvailable) {
    JRDesignImage jrDesignImage = new JRDesignImage(jasperDesign);
    expression = new JRDesignExpression();
    expression.setText("\"/path/to/image.png\"");
    jrDesignImage.setExpression(expression);
    jrDesignImage.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    jrDesignImage.setX(400);
    jrDesignImage.setY(25);
    jrDesignImage.setWidth(93);
    jrDesignImage.setHeight(100);
    jrDesignImage.setScaleImage(ScaleImageEnum.RETAIN_SHAPE);
    band.addElement(jrDesignImage);
    textField.setX(10);//Your desired x position when image is available.
    textField.setY(0);//Your desired y position when image is available.
  }

  band.addElement(textField);
  jasperDesign.setTitle(band);
  return jasperDesign;
}

喜欢编码。

你可以动态地进行编码。你能描述一下。。。。