【问题标题】:JTable cell text space not shown when print out打印输出时未显示 JTable 单元格文本空间
【发布时间】: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


【解决方案1】:

这是由于 JTable 的“Microsoft Sans Serif”字体造成的。我将字体更改为“Tahoma”。它有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-29
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    相关资源
    最近更新 更多