Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        6年前关闭。
                                                                                            
                
        
我有以下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()方法?

最佳答案

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

尝试此操作以确保在设置文本后它可以工作。

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

07-24 18:58
查看更多