Jump to content

ljubob

Recommended Posts

Hello,

I have a problem with textField word wrap that does not work correctly in every case.
Sometimes the right part of the text is not visible and also wrapping does not happen.

If I change fontName variable (in source code) to Arial it works but not with Lucida and some other fonts.
If I set fontName attribute in XML to Lucida Sans it works.

But in this case right part of the text is not visible on the report.

I don't have any other idea because wrapping (isStretchWithOverflow) works only in some cases (texts) and with some fonts.
I tested this on Windows XP. On Linux works fine.

Code:
demo.jrxml<?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="d" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">  <property name="ireport.zoom" value="1.0"/>  <property name="ireport.x" value="0"/>  <property name="ireport.y" value="0"/>  <field name="field1" class="java.lang.String"/>  <detail>    <band height="21" splitType="Stretch">      <textField isStretchWithOverflow="true">        <reportElement x="110" y="0" width="158" height="20"/>        <textElement>          <font size="9"/>        </textElement>        <textFieldExpression class="java.lang.String"><![CDATA[$F{field1}]]></textFieldExpression>      </textField>    </band>  </detail></jasperReport>import javax.swing.*;import net.sf.jasperreports.engine.*;import net.sf.jasperreports.engine.design.*;import net.sf.jasperreports.engine.xml.*;import net.sf.jasperreports.swing.*;public class WrapBug extends JFrame {  private final String jrxml = "/tmp/jasperwidth/src/jasperwidth/demonstrate/demo.jrxml";  private final String[] txt = {    "Testing sometext 1234-sometext_1", // OK: display in one line    "Testing sometext 1234-sometext_12345", // OK: wrap some text    "Testing sometext 1234-sometext_12" // FAIL: "sometext_12" not visible  };  private final String fontName = "Lucida Sans";  public static void main(String[] args) {    new WrapBug().setVisible(true);  }  public WrapBug() {    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);    try {      JasperDesign jasperDesign = JRXmlLoader.load(jrxml);      JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);      JRDataSource ds = new JRDataSource() {        int cnt = -1;        @Override        public boolean next() throws JRException {          return ++cnt < txt.length;        }        @Override        public Object getFieldValue(JRField jrf) throws JRException {          return txt[cnt].toString();        }      };      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, ds);      JRDesignStyle style = new JRDesignStyle();      style.setName("my-style");      style.setDefault(true);      style.setFontName(fontName);      jasperPrint.addStyle(style);      add(new JRViewer(jasperPrint));      setSize(800, 600);    } catch (Exception e) {      e.printStackTrace();    }  }}
Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...