使用JComponentPack产品中的JPrintPreview和PrintFactory打印和打印预览控件

Use JPrintPreview and PrintFactory in JComponentPack


JPrintPreview is a Java Print Preview component in JComponentPack.

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

PrintFactory usage.

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.

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:

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

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)

奇新Java控件——Java控件提供商和Java RIA, Web, J2ME解决方案开发商

JComponentPack是基于Swing框架的Java GUI控件集合,它包括JDataGrid电子表格版本, JDataGrid数据库版本,JComponentSet--Java swing控件集。


了解更多产品。。。
  



--------------------------
新闻: 华硕上网本或将预装谷歌Android系统
导航: 博客园首页   知识库   新闻   招聘   社区   小组   博问   网摘   找找看

你可能感兴趣的:(使用JComponentPack产品中的JPrintPreview和PrintFactory打印和打印预览控件)