如何从Java应用程序发送JTable数据到打印作业?

问题描述:

在我的应用程序中,我有一个带数据的JTable,我需要添加一个打印按钮,它可以在打印纸上的表格中添加打印数据的功能(发送打印机作业),如何使用 PrinterJob'类?
我一直在寻找示例,但是我找不到一个从JComponent打印一些数据的简单示例。

In my Application, I have a JTable with data and I need to add a print button which adds the functionality of printing the data in a table on printer paper (send a printer job), how is that possible using the PrinterJob' class? I've been searching around for examples, but I couldn't find a simple example that prints some data from a JComponent.

这是其中一个我找到的网站: http://java.sun.com/products /java-media/2D/forDevelopers/sdk12print.html
但我不确定要关注什么才能理解打印的工作原理(页面格式等)。

This is one of the Websites I found: http://java.sun.com/products/java-media/2D/forDevelopers/sdk12print.html. But I am not sure what to focus on to understand how printing works (page format ...etc).

谢谢

嗯,

今天关于打印的Java6 Oracle tutotial http://download.oracle.com/javase/tutorial/2d/printing/index.html 包含 http://download.oracle .com / javase / 7 / docs / api / javax / swing / JTable.html #print%28%29 ,在 JTable教程,包括 Runnable Examples ,然后你必须搜索(在这个论坛上)正确打印分页和方向

todays Java6 Oracle tutotial about printing http://download.oracle.com/javase/tutorial/2d/printing/index.html contains http://download.oracle.com/javase/7/docs/api/javax/swing/JTable.html#print%28%29 which is described in JTable Tutorial including Runnable Examples, then you have to search (on this forum too) for correct Print paginations and orientations

例如

PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
set.add(OrientationRequested.LANDSCAPE);
resultFxTable.print(JTable.PrintMode.FIT_WIDTH, header, footer, false, set, false);

注意:我不确定是否可以为PrintHeader和PrintFooter正确设置Font,FontSize和FOntColor用于JTable打印

note: I'm not sure that is possible correctly set Font, FontSize and FOntColor for PrintHeader and PrintFooter for JTable Printing