You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DynamicJasper:如何设置globalFooterVariable样式及报表全局字体大小?

Answer

Great question! Let's break this down into two clear parts: styling your global footer sum variables and adjusting the overall report font size (since your code uses drb from the DynamicReports library).

To apply custom styling (like bold text, alignment, color, or font size) to your footer sum variables, you’ll create a StyleBuilder and pass it as an extra parameter when calling addGlobalFooterVariable().

First, define your footer style using DynamicReports’ stl utility class:

import net.sf.dynamicreports.report.builder.style.StyleBuilder;
import static net.sf.dynamicreports.report.builder.DynamicReports.stl;
import java.awt.Color;

// Build a custom style for footer sums
StyleBuilder footerSumStyle = stl.style()
    .bold() // Make text bold for emphasis
    .setFontSize(12) // Adjust footer font size
    .setTextAlignment(stl.textAlignment().right()) // Align numbers to the right (standard for sums)
    .setForegroundColor(Color.DARK_GRAY) // Optional: change text color
    .setBorder(stl.border().bottom(stl.pen1Point())); // Add a thin bottom border to separate sums

Then attach this style to each footer variable:

drb.addGlobalFooterVariable(totalAmount, DJCalculation.SUM, footerSumStyle);
drb.addGlobalFooterVariable(basicAmount, DJCalculation.SUM, footerSumStyle);
drb.addGlobalFooterVariable(cgstColumn, DJCalculation.SUM, footerSumStyle);
drb.addGlobalFooterVariable(sgstColumn, DJCalculation.SUM, footerSumStyle);

You can also create unique styles for individual variables if needed—just repeat the style-building step with different properties.

Adjusting the Entire Report's Font Size

To set a base font size for the whole report, define a default style and apply it to your report using setDefaultStyle(). All elements will inherit this style unless you override it for specific components.

// Create a default style with your desired base font size
StyleBuilder defaultReportStyle = stl.style()
    .setFontSize(10); // Set your preferred base font size here

// Apply the default style to the report
drb.setDefaultStyle(defaultReportStyle);

If you want certain elements (like headers, titles, or specific columns) to have a different size, override the default style for those components:

// Example: Larger, bold title style
StyleBuilder titleStyle = stl.style(defaultReportStyle)
    .setFontSize(16)
    .bold();

drb.title(drb.text("Monthly Tax Report").setStyle(titleStyle));

Bonus: Extra Styling Tips

You can tweak your footer style even more with these common options:

  • .setPadding(stl.padding().top(5).bottom(5)): Add vertical padding to the footer row
  • .setBackgroundColor(Color.LIGHT_GRAY): Add a subtle background color to highlight sums
  • .setFontName("Arial"): Change the font family for the footer text

内容的提问来源于stack exchange,提问作者Preciso Sensedge

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:54:15