Results 1 to 2 of 2
Thread: Printing Help...
- 02-16-2009, 12:12 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 14
- Rep Power
- 0
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....
- 02-17-2009, 07:07 AM #2
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 13
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 :
Java 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();
Similar Threads
-
Help in Printing
By kirly in forum Advanced JavaReplies: 3Last Post: 10-03-2011, 04:40 PM -
Simple Printing Example
By Java Tip in forum SWT TipsReplies: 0Last Post: 07-11-2008, 05:41 PM -
Printing Example
By Java Tip in forum SWT TipsReplies: 0Last Post: 07-11-2008, 05:41 PM -
Help Printing Tables
By ogidantunde in forum Advanced JavaReplies: 0Last Post: 06-14-2008, 07:34 PM -
Printing (no dialog)
By Java Tip in forum Java TipReplies: 0Last Post: 02-04-2008, 10:36 AM
Bookmarks