2014-01-14 123 views
1

我有以下JTextAreaJTextArea.print()打印空白页

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()方法吗?

+0

你在屏幕上看到了什么?因为您没有附加任何文字 – nachokk

回答

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(); 
    } 
} 
+0

不,该文本在应用程序的其他位置设置。 – Neeko

+0

@Neeko我猜它没有设置,因为如果我只执行我提供的代码(例如在主要方法中),它就可以工作。但是这里有一些你应该检查的东西:你确定文本是否被设置?你确定没有人将前景色和背景色设置为白色吗? –

+0

不,文本在应用程序的其他地方设置 - 我投票结束你的问题(当然没有选项 - 射进黑暗) – mKorbel