mperezfe Posted January 11, 2011 Share Posted January 11, 2011 Hi @ll,I'm trying to highlight a text inside a text field as it is done in most of text editors.I know how to set a background color for the complete text field area, but I cannot do it just for the text inside.I'm using iReports 2.0.4.Thanks for your answers!Maria Link to comment Share on other sites More sharing options...
mdahlman Posted January 11, 2011 Share Posted January 11, 2011 Refer to the sample demo/samples/styledtext that ships with JasperReports and iReport.Regards,Matt Link to comment Share on other sites More sharing options...
cbarlow3 Posted January 11, 2011 Share Posted January 11, 2011 Great report. In the report inspector, select the root node (the name of the report), and then in the Properties pane, select "All Sections, No Detail" from the dropdown box for the property that is called "When No Data". This sample report has no query and no detail band, so if you don't select this option, you may see the goods in the designer pane and then just get a blank page when you go to actually preview.I'll definitely keep this sample file handy.Carl Link to comment Share on other sites More sharing options...
mperezfe Posted January 12, 2011 Author Share Posted January 12, 2011 Thank you very much! I could fix my problem.I agree that this report is extremely useful. It woul be nice if it includes some examples by using an expresion with a field, in addition to static text.Regards,Maria Link to comment Share on other sites More sharing options...
cbarlow3 Posted January 12, 2011 Share Posted January 12, 2011 The main downside to including a text field in the example is that it would have to use a query, and of course that would typically mean that you couldn't run it right out of the box, because the query would make the report specific to a certain database (actually, I maintain that you could use a CTE and a Values() statement to avoid that problem). But I wanted to make sure I wasn't going to have any problems when I tried this with fields, variables, etc., so on the text field that has text "This text field element contains..." I changed the end of that text field expression from "...text." to text. POSTING_DATE: <style forecolor=\"red\">"+$F{POSTING_DATE}+"</style>"and it worked great: the posting date printed in red, even though the text immediately before it was in black.I pasted the jrxml for just that one field below. One thing I miss with dates and currency fields, etc. is the ability to use a pattern. So far, most of my reports have been of the variety where I can display a money, date, etc. field separately from other data, but if I had to embed a date or amount in the middle of a sentence, for example, I don't think I'd be able to take advantage of the built-in Pattern functionality of a text field, would I? I'd instead have to use Groovy, JavaScript, etc. to convert my value into the appropriately patterned string, right?If there's a way to apply a pattern to just a part of a text field the same way you can apply this styled markup to individual components of a text field, that would be extremely useful when I get around to writing reports that are actually letters, notices, etc. instead of column-style reports.CarlCode: <textField> <reportElement x="0" y="150" width="555" height="60"/> <textElement textAlignment="Center" markup="styled"> <font size="16"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["This text field element contains styled text displaying the text-only version of the <style size=\"12\" isBold=\"true\" forecolor=\"black\">^<style forecolor=\"#808080\">Jasper</style><style forecolor=\"#990000\">Reports</style></style> logo and some <font size=\"10\"><sup>superscript</sup></font> text and <font size=\"10\"><sub>subscript</sub></font> text. POSTING_DATE: <style forecolor=\"red\">"+$F{POSTING_DATE}+"</style>"]]></textFieldExpression> </textField> Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now