xaelophorus 0 Newbie Poster

I've created a class called PrintableReport that uses Java2D to paint a report from a database table to the screen. The user can then click the PRINT button to send the report to the printer. However, the printed page's formatting is not consistent with the onscreen formatting.

In particular, class PrintableReport (extends JComponent) contains three subcomponents: ReportHeader, ReportBody, and ReportFooter (all also extending JComponent). All classes override paintComponent(Graphics g). The formatting problem only occurs in ReportBody.

Example call order:

  1. PrintableReport.paintComponent(g) calls paintComponent(g) for ReportHeader, ReportBody, and ReportFooter.
  2. ReportBody contains a parameterized ArrayList of type BodyUnit. BodyUnit extends JComponent and overrides paintComponent(Graphics g). ReportBody.paintComponent(g) calls the paintComponent(g) method for each BodyUnit in the ArrayList.

This is all designed to produce a report as follows:
Header
BodyItem
BodyItem
BodyItem
Footer

The problem: the ReportBody class prints a horizontal line between each instance of BodyUnit. The spacing must be exact. This works perfectly for onscreen painting, but there is additional space between each item when the report is printed. Any idea of what may cause this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.