JTextArea.print()打印一个空白页面

时间:2014-01-14 13:10:43

标签: java swing printing

我有以下JTextArea

reportText = new JTextArea();
reportText.setColumns(100);
reportText.setLineWrap(true);
reportText.setName("Output Report");
reportText.setAutoscrolls(true);
reportText.setFont(new Font("Courier", Font.PLAIN, 12));
reportText.setEditable(false);
reportText.setSize(new Dimension(300, 500));

我只是想通过reportText打印reportView.getReportTextArea().print();中的文字。但是,打印机最终会打印一个空白页。我见过following SO answer,但我设定的尺寸让我不认为这是我的问题。

请注意,我稍后会在应用程序中设置文本,我在这里没有显示。

还有什么我想念的吗?我误解了JTextComponent.print()方法吗?

1 个答案:

答案 0 :(得分:2)

我想您要打印字符串"Output Report",但是您必须将其设置为JTextArea的文本而不是名称。

尝试此操作以查看在设置文本时它是否有效。

public class Main {
    public static void main(String[] args) throws PrinterException {
        JTextArea reportText = new JTextArea();
        reportText.setText("Output Report");
        reportText.print();
    }
}
相关问题