printing JPanel without displaying it to screen

时间秒杀一切 提交于 2019-12-26 04:01:31

问题


I have 2 classes. The first class contains a JPanel to be printed out. The second class prints the JPanel of the first class. How can I printout the JPanel of the first class without displaying it in to screen?


回答1:


Try the Sreen Image class.




回答2:


atlernative for your questions, because Swing APIs can do that

for JComponents which are layed by using Absolute Positioning didn't required to be visible for obtains final size,

1/ disadvantages

Absolute Layout setLaout(null) is last property how to layout JComponents

have to to create two Top-Level Containers

  • a) JFrame for visible JComponents
  • b) JDialog for printing output to the Printer

forgout yout that that you'll create this JDialog on fly, because then your aplication will hold maybe 100Mb or 500Mb of RAM, create JDialog only once time and its contents put to the JPanel and after printing remove JPanel from JDialog for another reusing, be ensure that you set for

myDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

2/ advantages

that is possible :-)



来源:https://stackoverflow.com/questions/6165751/printing-jpanel-without-displaying-it-to-screen

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