Everything You Need to Know About JClass PageLayout

Anyone who has money invested in a 401K has received a statement that shows the current balances of their investments with requisite charts and tables illustrating their performance over time.  Often times companies are required to produce documents with data in an elegant manner that is suitable for printing as well as online display.


JClass PageLayout offers Java developers set of components for adding paginated document output to Java applications.  The classes and methods of this component allow for precise control over the layout and formatting of the documents you create.  You can create sophisticated print output with columns, multiple fonts and styles, as well as predefined headers and footers. You will also find options for handling the rendering of tables and formulas within those tables.  You can then send the output to your system printer, display it in a print preview window, or format it into a PCL, PostScript, or PDF file.



The initial step for creating a document with JClass PageLayout is to select or define a template (which are written in XML).  


First and foremost the templates specify the physical size and orientation of the page.  Within the page you will define the location and size of the “frames” that will hold particular text (such as headers and footers) as well as images.  


Frames may contain multiple columns or you can add content to them using macros.  There’s a predefined macro to number pages and you may create additional custom macros that allow you to insert text that’s of dynamically generated at run-time.  


Furthermore the template will include instructions as to the the order text progresses through those frames (i.e “flow”) as well as and the next page to generate when the existing page and/or section is full.


Below is a sample XML document that defines an 8.5 x 11 (US Letter) page template that includes a header and a footer. Both these additional frames are three quarters of an inch in height, with the header color grey and the footer colored pink.  The body is divided into two columns:


<?xml version="1.0"?>


<PAGE NAME="8p5x11" UNIT="inches">

<LOCATION X="0" Y="0"/>

<SIZE WIDTH="8.5" HEIGHT="11"/>

<FRAME NAME="header" UNIT="inches" COLOR="grey"> 

<LOCATION X=“0.75" Y="0.25"/> 

<SIZE WIDTH="6.5" HEIGHT="0.75"/> </FRAME> 

<FRAME NAME="body" UNIT="inches"> <LOCATION X=“0.75" Y=“1.25"/>



<FRAME NAME="footer" UNIT="inches" COLOR="pink"> 

<LOCATION X=“0.75" Y="10.25"/> 

<SIZE WIDTH="6.5" HEIGHT="0.75"/> </FRAME> 

<FLOWFRAME NAME="body"/> <FLOWPAGE NAME="8p5x11"/> 




The above template code would be rendered as follows (borders are for illustrative purposes only):

JClass PageLayout Example


While a template defines where the text gets rendered on a page, there are additional classes within JClass PageLayout to control the flow of text from one frame to the next and from one page to the next. In cases where text is to flow from frame to frame, the page template specifies the basic flow of text within a document. However, at times you may want to advance the flow before it reaches the end of the current frame or page. For example, on a title page, you may want to insert the text containing the document title into a frame you’ve named Title, then advance the flow to print the author’s name into another frame you’ve named Author.  


The flow controls of JClass PageLayout allow you to add new text, lines or paragraphs to the current frame.  Alternatively you may advance through the flow to the next column, frame, or page of the document. When printing text, the flow components can determine if there is adequate spacing for the text within the frame as well as make proper adjustments to the height of a line of text and its baseline.


Formatting Text

The JCTextStyle class gives you control over the appearance of text in your document output. You can create documents with several styles for different types of paragraphs, such as headings, addresses, indented block quotes, and so on. Standard emphasis options such as bold, italic and underline are available as are superscript and subscript. You can use any of the standard styles that come with JClass PageLayout, or you can create and modify your own styles.  You may add your own custom fonts through font-metrics files or, fo PDFs, TrueType font (.ttf) files.



The JCPageTable components allows you to add a table to your document to display your data.  You will be able to define the flow of data into the table, specify the number of columns, add a header row, and control what the borders and background colors look like.  You can customize cell alignment and borders as well as make cells span across multiple rows or column borders. 


You can extract table data along with simple text formatting from JClass JCTables and Swing JTables. You can also extract the data from a SQL query using a JDBC result set.



JClass PageLayout has special capabilities for working with mathematical objects. The classes encapsulate a variety of useful mathematical expressions including calculating Sums, the Geometric Mean, Median, or Standard deviation with operands that may be scalars, vectors (in the mathematical/linear algebra sense), or matrices. These objects may then be stored as the generalized values of cells in a JClass PageLayout table where they may be evaluated at run time to produce results based on the data that has been inputted. You may perform an operation over a range of cells from the table using “expression lists.”


Images and Other Embedded Objects

Images may be added to a document simply by loading an image file into an Image object so it can be rendered into a frame or flow.   There are three options for rendering — embedding, floating or pasting.  Embedding places the image on the current line of text, which will wrap if there is not enough space on the current line to hold the image.  Floating an image inserts it on its own line. If there is not enough space on the page to hold the image, it “floats” to a roomier location, for example, the top of the next page (for this reason, floating is often used for larger graphics). Pasting an image locks the image at a set of coordinates you define. This option is used to import images that must always appear at the same location, such as a logo in company letterhead. 

Additionally JClass PageLayout is capable of importing and displaying a visual object, such as a JClass Chart, so long as the object is of type java.awt.Component. PageLayout can also draw and print a variety of geometric shapes, including lines, circles, rectangles, rounded rectangles, and polygons.


For a limited time, Scout Solutions is offering a free upgrade to our new and improved version of JClass PageLayout. With the purchase of a support plan, you will receive access to our dedicated expert JClass Support team that can fix technical issues and answer any questions. Save yourself the trouble of upgrading to a new software and receive access to our expert support team with the purchase of a new license and support agreement. Contact us to request your free upgrade and see for yourself how PageLayout can help you develop Java apps.


Request your free upgrade