Arquivo da tag: JasperReports

Style a text field in JasperReports

Yes, you can apply style for textField elements.

iReport using

The sample of report’s template:
[code type=xml]

:” + $F{TASKS_SUBTASK} + “ \n “]]>

The quote from iReport Ultimate Guide about markup attribute:

This Markup attribute allows you to format the text using a specific markup language. This is extremely useful when you have to print some text that is pre-formatted, that is, in HTML or RTF. Simple HTML style tags (like for bold and for Italic) can be used in example to highlight a particular chunk of the text. The possible values are as follows:

  • None
    No processing on the text is performed, and the text is printed exactly like it is provided.
  • Styled
    This markup is capable to format the text using a set of HTML-like tags and it is pretty popular in the Java environments. It allows to set a specific font for chunks of text, color, background, style and so on. It’s often good enough to format the text programmatically.
  • HTML
    If you want to print some HTML text into your report, this is what you need, but it’s primary use is to format text, so don’t expect to be able to print tables or add images.
  • RTF
    Setting the markup to this value, the content will be interpreted as RTF code. RTF is a popular document format stored in pure text. The little piece of text saying “this is a text formatted in RTF” in Illustration 19 has been generated using the string:
    {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\fnil\fprq2\fcharset0 Swift;}} {*\generator Msftedit;}\viewkind4\uc1\pard\f0\fs20 This is a text \f1\fs52 formatted \f0\fs20 in RTF\par }
    The string is actually an RTF file created using a simple word processor.
  • Report font
    This is the name of a preset font, from which will be taken all the character properties. This attribute is deprecated and it is there only for compatibility reason (that’s why it the label is strukethrough. In order to define a particular style of text to use all over your document, use a style.

The sample of using markup is here.

You can use style for setting:


  • Common properties
  • Graphics properties
  • Border and padding properties
  • Text propertiesThe another sample is here.

    DynamicJasper API using

    In case using DynamicJasper API you can set style with help of class:
    [code type=java]
    AbstractColumn columnState = ColumnBuilder.getNew()
    .addColumnProperty(“state”, String.class.getName())
    .addTitle(“State”).addWidth(new Integer(85))

    The sample is here.

    JasperReports API using

    In case using JasperReports API you can set style, for example, with help of net.sf.jasperreports.engine.base .JRBasePrintText class:
    [code type=java]
    JRPrintText text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());

    The sample is here.


Share and Enjoy !