使用JComponentPack產品中的JPrintPreview和PrintFactory打印和打印預覽控件

Use JPrintPreview and PrintFactory in JComponentPackhtml


JPrintPreview is a Java Print Preview component in JComponentPack.java

PrintFactory is a utility class in com.zfqjava.swing package to generate printable in JComponentPack.數據庫

PrintFactory usage.api

createPrintable(Component comp, Map map)
createPrintable(Image image, Map map)
It need two parameters, the first is a instance of Image or a instance of Component, the second parameter is a instance of Map, the key of map could be all the properties of class PrintFactory.
For example:
Key: PrintFactory.MARGIN, describe the margin of page. Its value type must be java.awt.Insets, for example: new java.awt.Insets(5,5,5,5);  
Key: PrintFactory.HORIZONTAL_ALIGNMENT, describe the alignment of horizontal its value will be SwingConstants.LEFT or SwingConstants.RIGHT or SwingConstants.CENTER.
Key: PrintFactory.FOOTER_FONT, describe the font of footer, its value type need be java.awt.Font.
Key: PrintFactory.FOOTER_ICON, describe the icon of footer, its value type need be javax.swing.Icon.
Key: PrintFactory.FOOTER_FORMAT, describe the message format of footer, its value type need be java.text.MessageFormat.
Key: PrintFactory.FOOTER_TEXT_ALIGNMENT, describe the alignment of footer text, its value will be SwingConstants.LEFT or SwingConstants.RIGHT or SwingConstants.CENTER.
Key: PrintFactory.FOOTER_ICON_ALIGNMENT, describe the alignment of footer icon, its value will be SwingConstants.LEFT or SwingConstants.RIGHT or SwingConstants.CENTER.
Key: PrintFactory.SHOW_FOOTER_LINE, indicate whether show footer line. Its value will be true of false.
Key: PrintFactory.TABLE_SHOW_ROW_HEADER, Identifies whether show the row header of table. Its value type is java.lang.Boolean.
Key: PrintFactory.TABLE_SHOW_GRID_LINE, Identifies whether show the grid line of table. Its value type is java.lang.Boolean.
Key: PrintFactory.TABLE_PRINT_AREA, describe the area of table will be print , its value type is com.zfqjava.swing.cell.Cell.
Key: PrintFactory.FIT_WIDTH, Identifies whether auto fit page width, its value type is java.lang.Boolean.
Key: PrintFactory.KEEP_ASPECT_RADIO, Identifies keep the aspect radio for fit width or fit height
How to set footer icon and its alignment, use following statements is ok.,
 public Image getImage(URL url) {
      try {
          return ImageIO.read(url);
      } catch(Exception e) {
          e.printStackTrace();
          return null;
      }
}
URL url = getClass().getResource("/com/zfqjava/client/resources/images/logo.png");
   
 Map.put(PrintFactory.FOOTER_ICON, new ImageIcon(getImage(url)));
Map.put(PrintFactory.FOOTER_ICON_ALIGNMENT, SwingConstants.LEFT);

JPrintPreview usage.app

Example code:
JPrintPreview printPreview = new JPrintPreview();
PageFormat pageFormat = new PageFormat();
pageFormat.setOrientation(PageFormat.LANDSCAPE);
printPreview.setPageFormat(pageFormat); 
printPreview.setPrintData(PrintFactory.createPrintable(image,map)); 
//how to use PrintFactory, please see above.
printPreview.showFrame();

JPrintPreview could set page format, see the example code. For more information, please seejava.awt.print.PageFormat.框架

JPrintPreview have 7 methods to show:
url

The following three methods show the preview in the current window of parameter.spa

showInternalFrame( JInternalFrame internalFrame)
showFrame( JFrame frame)
showApplet( Applet applet)
The following four methods show the preview in a new window.
showFrame()
showFrame( String title)
showDialog( Component parent,  String title)
showDialog( Component parent)


--------------------------
新聞: 華碩上網本或將預裝谷歌Android系統
導航: 博客園首頁   知識庫   新聞   招聘   社區   小組   博問   網摘   找找看
相關文章
相關標籤/搜索