Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6626301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:52:36+00:00 2026-05-25T21:52:36+00:00

I am generating a report with that will have a 7 columns where the

  • 0

I am generating a report with that will have a 7 columns where the last 6 should have the the last 6 months listed. So as of the time of this writing it should be:

NAME -> September -> August -> July -> June -> May -> April

ss the column headers. I am trying to avoid having to pass them in as parameters, and am trying to get Jasper Reports to figure it out at runtime. I can get the first month pretty easily using a Text Field Expression. It looks like:

new java.text.SimpleDateFormat("MMMMM").format(new Date())

The issue comes in with the other months. I initially tried

new java.text.SimpleDateFormat("MMMMM").format(java.util.Calendar.getInstance().add(Calendar.MONTH, new Integer("-1)).getTime())

This does not work since Calendar.add does not return a Calendar instance. I then tried using a variable and then a combination of variables which also did not work.

How to make Jasper Reports programmatically determine the Name of Columns within the report it self?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:52:37+00:00Added an answer on May 25, 2026 at 9:52 pm

    I think the best approach to solving this problem is to use Commons Lang. That package provides utilities to make calculations like this very easy. By adding one extra jar you can then use expressions like this:

    DateUtils.addMonths(new Date(),-1)
    

    I find that easier to maintain than first creating a helper Calendar class and then using the ternary operator but ignoring its results.

    $P{cal}.add(Calendar.MONTH, -1)
    ? null : $P{cal}.getTime()
    

    If you ever need to generalize the solution then it’s a lot easier to get a Date back from a SQL query than to get a Calendar. So you can quickly change to "DateUtils.addMonths($F{MyDate},-1)". Initializing a Calendar to match a date returned by a query isn’t nearly as simple. But of course there’s a certain benefit to not having to add one more .jar file. So sometimes that ternary operator technique is the quickest way to get things done.

    I wrote about using the Commons Lang approach a couple of years ago here: http://mdahlman.wordpress.com/2009/09/09/jasperreports-first-dates/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a report which will give me the time field as $time='Wed, 25
I have a Java application that is generating JasperReports. It will create as many
I received reports that a my report generating application was not working. After my
I'm generating a query and report through VBA. I have an option of asking
my report is generating data that is supposed to be sorted by date and
I had a problem with date manipulation.This is my scenario.I have a daily generating
BACKGROUND I'm writing a method that will (eventually) take as input a System.Data.DataTable and
We have an ASP.NET application that queues some of its long-running operations (generating reports,
I'm generating a Crystal Reports report which will ultimately need to be split into
I am planning to create a small research web application, that will have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.