-
Printing Help...
Hey guys,
U all know all in java JComponent can be printed. But i want to preview them before printing in Landscape Orientation. I have done lots of digging & googling..
But most of the solutions for the previewing only the Printable object such as JtextPane, JEditorpane, textfields, textarea....
I have one JPanel in which i have lots of labels whose values are loaded from the database . for eg: marksheet of student....
Now i wanted to Preview this JPanel in some Preview window with capability of zooming & changing page orientation etc..
SO please guys anyone who has faced such problem or know the solution help me out...
Its really urgent....
Thanks in Advance....
-
Anything that's Printable has to render onto a graphics context, which means you can render it onto an offscreen buffer as well, and then display that. The steps are, create a BufferedImage of the desired size, get it's graphics context, call 'print' on your top level Printable with that graphics context, then display your image in another component :
Code:
final BufferedImage preview = new BufferedImage(...size etc...);
Graphics graphics = preview.getGraphics();
{your Printable}.print(g, {a suitable page format}, pageNum);
JComponent customComp = new JComponent() {
public void paintComponent(Graphics g) {
g.drawImage();
}
};
...add your compont to some content pane on some frame somwhere and see your preview...
...when all done, don't forget this!
graphics.dispose();