The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Creating a formatted printable report

Hi,
I'm not entirely sure about where to post this, but it's making me nuts.

I'm new to Java, but not to coding in general. I'm writing a program that reads Excel files, does some things under the users control, and then needs to PRINT a form.

I've gone through the Java printing lessons, I understand how to get stuff to print. I can make lines, and boxes, and text. The problem is formatting it. As far as I can see, the only way to build a printable form is in code, which is fine if all you want is some simple text and a line or two...

But this form itself is kind of complex, and will be several to dozens of pages (depending on how much data there is). I can't imagine how I'm going to convert it to a serials of g.drawRect and drawString commands without going completely mad in the process.

Surely there's another way that I just don't know about? A graphical program to lay out a printable report?

Appreciate any suggestions. I've attached a copy of the report so you can see what I mean by "kind of complex".

Re: Creating a formatted printable report

Well if you are reading Excel files, why not write Excel files? Depending on your Excel Library, you should be able to create an Excel file, formatted the way you like, and set the Print Specifications. I do something similar to this where I have a program that builds a 500 page printable report. My formatting and stuff is done in Excel. I simply open the Excel file afterwards and press print.

Alternatively, if the report is patterned, you can work with the patterns to create a dynamic GUI. I'll go more indepth if you want me to.

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: Creating a formatted printable report

To be honest I hadn't considered creating the report in Excel. I have a feeling the output would be just as hard to create that way. Sounds like a good idea for the next thing I have to do though.

What I was truly hoping for, was that there was a software tool that could be used to lay out a graphics page in the same way an IDE is used to lay out a GUI.

By dynamic GUI, are you suggesting that I (for example) draw the data elements on the screen as if they were a user interface - presumably after hiding the original interface - then print that new interface?

Re: Creating a formatted printable report

Originally Posted by rjtan08

i have the exact same problem, does someone know any solution to this?
It is the same with "crystal reports" of visual studio.

There doesn't appear to be software to simplify this process in Java, at least not that I could find anywhere. What I'm doing is using my favorite design program (InDesign for me), setting it to show position as points (72 points/inch), and laying out the report there.

That makes it a lot easier to get the coordinates for my draw commands, I can just click the text box or line, and read the position data from InDesign, then type it into the command.

Re: Creating a formatted printable report

Originally Posted by bradleysm

By dynamic GUI, are you suggesting that I (for example) draw the data elements on the screen as if they were a user interface - presumably after hiding the original interface - then print that new interface?

Well, as with most things in programming, things can be made much easier with loops. I am suggesting something like a loop that will paint (or however you're doing it) the same chunk of elements however many times you tell it to. That way you only need to create one instance of the pattern, provide a buffer (space between each instance in the pattern), and tell it how many you want.

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: Creating a formatted printable report

Originally Posted by aussiemcgr

Well, as with most things in programming, things can be made much easier with loops. I am suggesting something like a loop that will paint (or however you're doing it) the same chunk of elements however many times you tell it to. That way you only need to create one instance of the pattern, provide a buffer (space between each instance in the pattern), and tell it how many you want.

Ah, yes. That's exactly what I ended up doing. Happily, the form did have a repeating section, so I only had to design it once and the header once. Some looping and a variable to keep track of how much to offset the pixels when placing the data kept everything aligned.

It was still a lot more labor intensive than I expected, having to create the printout essentially by hand by drawing lines and boxes from pixel to pixel. I guess I'm just surprised there's no GUI designer that, when done, produces a Printable class for you. Maybe when I get my skills polished up, that'll be my first major project.