【发布时间】:2021-08-13 08:31:20
【问题描述】:
打印表格的方法。
public static void PrintTable(JTable table,String title) {
try {
MessageFormat headerFormat = new MessageFormat(title);
MessageFormat footerFormat = new MessageFormat("{0}");
boolean complete = table.print(JTable.PrintMode.FIT_WIDTH,headerFormat, footerFormat);
if (complete) {
JOptionPane.showMessageDialog(null, "Printing Completed.");
}else {
JOptionPane.showMessageDialog(null, "Printing Canceled !");
}
} catch (PrinterException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null,e);
}
}
应用程序输出表列看起来像这样(正确)。
| Address |
:--------------------------
| Kathmandu Nepal
| Kirtipur 5 Kathmandu Nepal |
| Baneswor 10 Kathmandu Nepal |
| Balkhu 2 Kathmandu Nepal |
但是打印的硬拷贝是这样的:(有些单词之间缺少空格)。
| Address |
:------------------------
| Kathmandu Nepal
| Kirtipur5KathmanduNepal |
| Baneswor10KathmanduNepal |
| Balkhu2KathmanduNepal |
如何克服这个问题?我google了一下,没有找到相关的解决办法。
【问题讨论】:
-
也许可以展示您的 JTable 的创建方式、大小等?有趣的是 JTable.PrintMode.NORMAL 没有帮助......
标签: java swing printing jtable