JTextComponent.print();打印空白 [英] JTextComponent.print(); Prints Blank

查看:52
本文介绍了JTextComponent.print();打印空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种解决方案,根据用户 UI 内容动态生成文本和图像,然后在简单的单击"基础上进行打印.

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.

到目前为止,我的意图(通过做一点研究)是创建一个 JTextComponent,它的内容将根据用户的输入(间接)生成并简单地打印 JTextComponent.这个 JTextComponent 永远不会显示在 UI 的任何地方,只会打印出来.

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.

问题 1:这是一种可行的方法吗?

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

Q2:谁能告诉我为什么页面打印出来是空白的?

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

推荐答案

您应该设置报告的大小.在相反的情况下,它只是 0,0 大小.

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

这篇关于JTextComponent.print();打印空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆