问题
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