Results 1 to 2 of 2
  1. #1
    chiragkini is offline Member
    Join Date
    Jan 2009
    Posts
    14
    Rep Power
    0

    Default 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....

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    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

  1. Help in Printing
    By kirly in forum Advanced Java
    Replies: 3
    Last Post: 10-03-2011, 03:40 PM
  2. Simple Printing Example
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 04:41 PM
  3. Printing Example
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 04:41 PM
  4. Help Printing Tables
    By ogidantunde in forum Advanced Java
    Replies: 0
    Last Post: 06-14-2008, 06:34 PM
  5. Printing (no dialog)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-04-2008, 09:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •