我有应用程序生成具有自定义字体样式的报告,如字体系列,颜色,大小和样式(粗体,斜体,下划线)。我使用Windows系统中的所有font-family。
我尝试在.jrxml文件中使用参数。像这样:
<parameter name="fontFamily" class="java.awt.Font"/>
在文中:
<staticText>
<reportElement uuid="3c9d8704-dbae-49ed-9787-477ff5b8742f" x="4" y="4" width="241" height="15" forecolor="#FFFFFF"/>
<textElement verticalAlignment="Middle">
<font fontName="$P{fontFamily}" size="11" isBold="true"/>
</textElement>
<text><![CDATA[Hasil Pemeriksaan PROCEDURE]]></text>
</staticText>
当我在iReport中预览时,它会记录错误:
Error filling print... Font '$P{fontFamily}' is not available to the JVM. See the Javadoc for more details.
java.lang.NoSuchMethodException: java.awt.Font.<init>(java.lang.String)
at java.lang.Class.getConstructor0(Class.java:2730)
at java.lang.Class.getConstructor(Class.java:1676)
at com.jaspersoft.ireport.designer.compiler.prompt.Prompter$1.run(Prompter.java:278)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
请帮助我,谢谢你:)
答案 0 :(得分:1)
设置以下属性
Markup : html
Text field expression : "<font face='" + $P{fontName} + "'>" + $F{field1} + "</font>"
将$ P {fontName}的值设置为 Monospaced 和 SansSerif 之后,我可以看到差异。