TableLens table = …;
AttributeTableLens attr = new AttributeTableLens(table);
attr.setColAlignment(1, StyleConstants.H_RIGHT);
layout.addTable(attr);
|
View a 2-minute demonstration of InetSoft's easy, agile, and robust BI software. |
Another way to change the table attributes is to subclass a TableLens class and override the attribute getter methods. This requires slightly more work but is more efficient than the AttributeTableLens.
Landscape Printing
Landscape printing mode is often used to print reports with wide tables. Landscape printing is fully supported by InetSoft products, including all custom printer drivers.
Java2 Landscape Printing
The Java2 printing model requires the page format to be set when creating a print job. Therefore, you must set the correct page format separately. If the application knows the size of the paper and mode, the page format can be hardcoded by creating a PageFormat object by hand. Otherwise, the application can obtain a PageFormat object with the pageDialog() method in the PrinterJob:
PrinterJob job = StylePrinter.getPrinterJob();
PageFormat fmt = job.pageDialog();
The Java2 page format dialog has portrait and landscape reversed. Check the visual page on top of the dialog to see the correct printing mode.
The user is responsible to select the correct paper and printing mode in the page format dialog. Once a correct PageFormat object is created, it can be used to create a Pageable object using the inetsoft.report.j2d.StyleBook class.
StyleBook book = new StyleBook(report, fmt);
job.setPageable(book);
if(job.printDialog()) {
job.print();
}
Example: Landscape Printing
The following is an example using Java2 API to print in landscape mode. It uses a page format dialog to allow the user to select the printing mode.
Listing 9. Printing mode selection in Java2 (Landscape1_2.java)
printB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PrinterJob job = StylePrinter.getPrinterJob();
PageFormat fmt = job.pageDialog(job.defaultPage());
ReportSheet report = createReport();
StyleBook book = new StyleBook(report, fmt);
job.setPageable(book);
if(job.printDialog()) {
try {
job.print();
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
});
When using Previewer to view and print a report, the paper size needs to be passed to the Previewer when it is created. The orientation is passed directly from the ReportSheet object. This means that the end user does not need to select landscape-printing mode explicitly in the print dialog.
Note: The Java2 drivers implement landscape printing differently. When orientation is set to landscape, the Java2 printer drivers rotate the printing internally and always assume the printer is in portrait mode. The printer MUST be in PORTRAIT mode for landscape to work properly.
The following example shows this process.
Listing 10. Landscape printing through previewer (Landscape.java)
public static void main(String[] args) {
ReportEnv.setProperty("StyleReport.useCustomDriver",
"true");
ReportSheet report = createReport();
PreviewView previewer = Previewer.createPreviewer();
previewer.setExitOnClose(true);
double w = previewer.getPageWidth();
double h = previewer.getPageHeight();
previewer.setPageWidth(h);
previewer.setPageHeight(w);
report.setOrientation(StyleConstants.LANDSCAPE);
previewer.pack();
previewer.setVisible(true);
previewer.print(report);
}
The landscape printing method is slightly different from that of previous versions of Style Intelligence, which used page sizes to control the printing without regard for orientation settings. In the new approach, users are no longer required to set the printing mode manually.
More Articles About Report Formatting
Difference from Report Writers - The InetSoft package is a report generation tool, written in Java, designed to produce business reports. It differs from report writers in a number of important aspects: • Style Intelligence allows a Java program to create a report dynamically, using a variety of data sources. Traditional report writers only provide a visual interface to create a report and normally work directly with databases. • Style Intelligence can be easily extended with new styles and rendering methods. Traditional report writers normally have a fixed set of features and do not provide an API to extend their functionality. • Style Intelligence is tightly integrated with the application, both from a programming point of view and from an end user point of view. No separate application is needed to generate a report. Traditional report writers, on the other hand, normally require users to start another application separate from the main application...
Financial Data and Other Enterprise Data Mashups - At InetSoft, we specialize in providing data mashups not only with your organizations financial data but also with your organizations large network of databases including, but not limited to: relational databases (JDBC), multidimensional databases, XML, SOAP, Java beans (POJO), EJB beans, flat files, Excel spreadsheets, OLAP cubes, and the proprietary data stores from JDE, SAP, PeopleSoft, and Siebel CRM...
How To Print Reports in Java - InetSoft makes a Java reporting application for creating ad hoc and production reports to be printed, distributed by email, or posted to a Web portal for interactive viewing. InetSoft's BI software Style Report is an advanced printing and report generation Java-based application...
Java API-Based Printing - First we will address printing tables in reports. Using a very simple example we will describe the process for generating printed output containing a table. The Previewer is a frame component that can be used to preview a report. The previewer is Java2 based and provides support for Java2 printing API...
PDF Printer for Reports - The PDF Printer called from the API is a simpler version of the PDF3Generator. The PDFPrinter lacks support for generating tables and TOC (Table of Contents). To create a PDFPrinter, pass a File object or a FileOutputStream to the constructor...