|
import java.awt.*;
import javax.swing.*;
import com.wildcrest.j2printerworks.*;
class J2ComponentPrinterSimplestTest {
static public void main(String args[]){
JLabel label = new JLabel();
label.setFont(new Font("Serif",Font.PLAIN,14));
label.setText("<html>This is an example of <i>a JLabel</i><br>"
+ "placed inside a <u>J2ComponentPrinter</u> and<br>"
+ "printed using <b>J2PrinterWorks</b></html>");
label.setPreferredSize(new Dimension(250,75);
JFrame frame = new JFrame("J2ComponentPrinter test");
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
J2Printer printer = new J2Printer();
printer.setSeparatePrintThread(false);
J2ComponentPrinter componentPrinter = new J2ComponentPrinter(label);
printer.addPageable(componentPrinter);
printer.print();
System.exit(0);
}
}
Most of the methods of J2ComponentPrinter are set and get methods for controlling its property values. The full list of J2ComponentPrinter methods, what they do, and their default values are given in the J2ComponentPrinter Javadoc documentation.
General properties
Whether J2ComponentPrinter is used as a Pageable or a Flowable, you can control whether the J2ComponentPrinter operates in shrink-to-fit,, tile, break-on-components, or break-on-color mode, whether it is left, right, or center justified horizontally on a page, top, bottom, or center justified within the remaining space on a page, whether to use a white background when printing the JPanel, and whether to draw an outside line around the JPanel.
Horizontal and vertical pagination modes
J2ComponentPrinter has four modes for controlling the horizontal and vertical pagination of the JPanel to be printed, SHRINK_TO_FIT, TILE, BREAK_ON_COMPONENTS, and BREAK_ON_COLOR described above in the section J2ComponentPrinter Pagination. To control the pagination mode of J2ComponentPrinter, use the following methods:
setHorizontalPageRule (int horizontalPageRule): Sets the horizontal page rule for mapping each Component into the printed page.
setVerticalPageRule (int verticalPageRule): Sets the vertical page rule for mapping each Component into the printed page.
Horizontal and vertical alignment
J2ComponentPrinter will print your Component either left, center, or right justified horizontally on the page between the left and right margins. The default value for horizontal alignment is CENTER.
Similarly, J2ComponentPrinter will print your Component either top, center, or bottom justified vertically on the page between the gap below the header and gap above the footer. The default value for vertical alignment is TOP.
setHorizontalAlignment (int horizontalAlignment): Sets the horizontal alignment (LEFT, CENTER, RIGHT) for printing the Component on the page.
setVerticalAlignment (int verticalAlignment): Sets the vertical alignment (TOP, CENTER, BOTTOM) for printing the Component on the page.
White background
By default, J2ComponentPrinter will print your Component with the Component background color, which might be the background color of the window in which it is displayed. You can specify whether whether the Component when printed should have a white background using the method:
setWhiteBackground (boolean whiteBackground): Sets whether to print the Component with a white background.
Outside line
J2ComponentPrinter lets you control whether to draw a line surrounding the Component and what color this line should be using the following methods:
setOutsideLines (boolean showOutsideLines): Sets whether to print outside border lines around Component.
setOutsideLineColor (java.awt.Color outsideLineColor): Sets Color of outside border lines.
« »
|