JTextComponent.print(); Prints Blank

拥有回忆 提交于 2019-12-11 20:29:05

问题


I am looking for a solution where text and images are dynamically generated based on user UI content, and then printed on a simple "one click" basis.

My intention thus far (from having done a little research) is to create a JTextComponent who's content will be generated based on the user's input (indirectly) and simply print the JTextComponent. This JTextComponent will never be displayed in the UI anywhere, only printed.

So far I set up a temporary test using;

    JTextArea report = new JTextArea("Test Text");
        try {
            report.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }

This brings up the print menu correctly (I will later specify against the menu coming up at all) but prints a blank page.

Q1: Is this a viable way of going about this?

Q2: Can anyone tell me why the pages are printing blank?


回答1:


You should set the report's size. In opposite case it's just 0,0 sized.



来源:https://stackoverflow.com/questions/19379469/jtextcomponent-print-prints-blank

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!